Date: Fri, 5 Jun 2009 18:52:07 +1000 (EST) From: Bruce Evans <brde@optusnet.com.au> To: Stanislav Sedov <stas@freebsd.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Benno Rice <benno@freebsd.org> Subject: Re: svn commit: r193475 - head/sbin/kldload Message-ID: <20090605182104.S15688@delplex.bde.org> In-Reply-To: <20090605102431.4769115f.stas@FreeBSD.org> References: <200906042343.n54Nh8c5008164@svn.freebsd.org> <20090605102431.4769115f.stas@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 5 Jun 2009, Stanislav Sedov wrote: > On Thu, 4 Jun 2009 23:43:08 +0000 (UTC) > Benno Rice <benno@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090605182104.S15688>