[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sakura-2.4.2 hurd patch (PATH_MAX)



Tanguy LE CARROUR, le Fri 03 Feb 2012 14:51:05 +0100, a écrit :
> TODO: do I have to report an error if malloc() or lstat() fails?

See the code around whether it usually does it.

> --- old/sakura-2.4.2/src/sakura.c	2012-02-03 14:18:51.789612191 +0100
> +++ sakura-2.4.2/src/sakura.c	2012-02-03 14:34:26.000000000 +0100
> @@ -1378,17 +1378,33 @@
>  
>  	if (term->pid >= 0) {
>  		char *file;
> -		char buf[PATH_MAX+1];
> +		char *buf = NULL;
> +		struct stat sb;
>  		int len;
>  
> +		if (lstat(file, &sb) == -1) {
> +			/* TODO: report error? */
> +			return cwd;

Keep the same behavior as before the patch: originally readlink would
fail and cwd just not be set. Do the same.

> +		}
> +		buf = malloc(sb.st_size + 1);
> +		if (buf == NULL) {
> +			/* TODO: report error? */
> +			return cwd;
> +		}
>  		file = g_strdup_printf ("/proc/%d/cwd", term->pid);
> -		len = readlink (file, buf, sizeof (buf) - 1);

So upstream code does not check for g_strdup_printf failure to allocate
room, so don't bother with checking the result of malloc().

> +		len = readlink (file, buf, sb.st_size + 1);
>  
> +		if (len < 0 || len > sb.st_size) {
> +			/* TODO: report error? */
> +			g_free(buf);
> +			return cwd;
> +		}
>  		if (len > 0 && buf[0] == '/') {
>  			buf[len] = '\0';
>  			cwd = g_strdup(buf);
>  		}
>  
> +		g_free(buf);
>  		g_free(file);
>  	}
>  


Reply to: