svn commit: r193475 - head/sbin/kldload

Bruce Evans brde at optusnet.com.au
Fri Jun 5 08:52:12 UTC 2009


On Fri, 5 Jun 2009, Stanislav Sedov wrote:

> On Thu, 4 Jun 2009 23:43:08 +0000 (UTC)
> Benno Rice <benno at FreeBSD.org> mentioned:

>> [... not quoted]

The broken pathname lookup and broken path separator should be in the
BUGS section (also in kld syscall manpages).  The namespace for the
`file' parameter of kldload(2) is completely undocumented in kldload.2.
It seems to be the same as the usual namespace for files, except for
large complications and undocumentations from having the pathname
search and the file extension magic in the kernel.

>> +	if (path == NULL) {
>> +		err(1, "allocating %lu bytes for the path",
>> +		    (unsigned long)pathlen + 1);
>                    ^^^^^^^^^^^^^^^^^^^^^^
> Why convert pathlen to unsigned long here? The pathlen variable is
> of size_t type which is already unsigned and we have the special 'z' prefix
> in printf(3) to print those.

Well, %z might be wrong since only the pathlen variable is of type size_t.
The expression `pathlen + 1' has type:

 	__binarypromoteof(__typeof(pathlen), int)),

so if size_t is smaller than int then the promotions are non-null and give
a type larger than size_t, and %z is wrong.  To use %z, the expression
should be written as (size_t)(pathlen + 1).

OTOH, the committed version has no type mismatch, since

 	__binarypromoteof(unsigned long, int)) = unsigned long,

and all versions should have no problems with overflow in the addition
or in the cast since pathlen should be small (even if unsigned long is
smaller than size_t, pathlen should be < ULONG_MAX - 1 so that everything
fits).

Bruce


More information about the svn-src-head mailing list