Date: Mon, 15 Jul 2002 14:14:36 +0300 From: Giorgos Keramidas <keramida@FreeBSD.org> To: Bruce Evans <bde@zeta.org.au> Cc: Dag-Erling Smorgrav <des@ofug.org>, freebsd-audit@FreeBSD.org Subject: Re: bin/ln & WARNS=5 Message-ID: <20020715111436.GD50130@hades.hell.gr> In-Reply-To: <20020715202126.S40071-100000@gamplex.bde.org> References: <xzpele59w21.fsf@flood.ping.uio.no> <20020715202126.S40071-100000@gamplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2002-07-15 20:25 +0000, Bruce Evans wrote:
> On 15 Jul 2002, Dag-Erling Smorgrav wrote:
>
> > Giorgos Keramidas <keramida@FreeBSD.org> writes:
> > > The following allows me to build bin/ln with WARNS=5 on i386.
> > > Does it look OK, or have I missed something important?
> >
> > I'd rather cast sizeof to int.
>
> That would break the possibly-intentional check for snprintf() failing.
> (size_t)-1 >= sizeof(path), but !(-1 >= (int)sizeof(path)).
My intuition was that size_t being unsigned won't require truncation
of the (int) return value... But if one wanted to explicitly make
both a check for (-1) and the return value being less than the size of
the buffer would the following be more proper?
%%%
Index: ln.c
===================================================================
RCS file: /home/ncvs/src/bin/ln/ln.c,v
retrieving revision 1.28
diff -u -r1.28 ln.c
--- ln.c 30 Jun 2002 05:13:54 -0000 1.28
+++ ln.c 15 Jul 2002 11:12:13 -0000
@@ -163,6 +163,7 @@
const char *p;
int ch, exists, first;
char path[PATH_MAX];
+ int pathlen;
if (!sflag) {
/* If target doesn't exist, quit now. */
@@ -189,8 +190,8 @@
p = target;
else
++p;
- if (snprintf(path, sizeof(path), "%s/%s", source, p) >=
- sizeof(path)) {
+ if ((pathlen = snprintf(path, sizeof(path), "%s/%s",
+ source, p)) == -1 || pathlen >= (int)sizeof(path)) {
errno = ENAMETOOLONG;
warn("%s", target);
return (1);
%%%
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020715111436.GD50130>
