hal: type bug in hal_hotplug.c

David Zeuthen david at fubar.dk
Tue Mar 30 03:08:29 EEST 2004


On Tue, 2004-03-30 at 01:48, Robert Love wrote:
> Hi, David.
> 
> In tools/linux/hal_hotplug.c, sysfs_mnt_path is declared as
> 
> 	static char *sysfs_mnt_path[255];
> 
> I do not think the intention is for an array of pointers to char :)
> 
> Thankfully, everything just works, since the allocated space is larger
> than assumed, but there are a few compiler warnings.
> 
> Attached patch fixes the typo.
> 
> Also, uses "PATH_MAX" instead of the magic "255".
> 
> Finally, I marked the arrays of string constants "const char" since they
> are, and marking them only "char" discards the qualifier.
> 
> Patch is against CVS.
> 

Ah, thanks, applied. My bad to ignore the warnings in the first place.

> +		strncpy (path, sysfs_mnt_path, PATH_MAX);
> +		strncat (path, devpath, PATH_MAX);
> +		strncat (path, "/", PATH_MAX);
> +		strncat (path, file, PATH_MAX);

Btw, these are still a bit off, since path is only PATH_MAX and strncat
appends a maximum of PATH_MAX of src to dst, which means a potential
buffer overflow - udev uses a macro to implement a sane strncat, maybe
we should do the same?

Cheers,
David




More information about the xdg mailing list