Date: Wed, 19 Feb 97 17:05:29 CST From: Joe Greco <jgreco@solaria.sol.net> To: guido@gvr.win.tue.nl (Guido van Rooij) Cc: top@sonic.cris.net, audit-bin@freebsd.org, FreeBSD-hackers@freebsd.org Subject: Re: hmm Message-ID: <199702192305.RAA08083@solaria.sol.net> In-Reply-To: <199702192053.VAA02956@gvr.win.tue.nl> from "Guido van Rooij" at Feb 19, 97 09:53:45 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> > char *p; > > > > if ((p = argv[0]) == NULL) > > errx(2,"test: argc is zero"); Sanity check? I can't think of any cases where this would happen, but maybe some kernel god would correct me. > It seems a bit strange to me. Just like the first part of the line > underneath btw: > if (*p != '\0' && p[strlen(p) - 1] == '[') { > ^^^^^^^^^^ That's sort of obvious, at least in the context of the second part of the expression... If you want to see if the last character in a string is '[', that is a very fast way to do it ( p[strlen(p) - 1] == '[' ). However, in the case where *p points to a zero-length string (i.e. argc[1] = ""), the expression evaluates to an invalid case: strlen(p) = 0, and 0 - 1 = -1. Taking the -1'th element of p[] is WRONG WRONG WRONG. But the ONLY time that this can happen is if you have a null string. So check for it first. It's simply a test looking for an argument that ends with the character '['. It is precisely correct, with the assumption that p is a valid, non-NULL, null terminated string of some sort. (Alternate way to think of it: If you have a zero length string, it obviously can not end in '[') ... Joe ------------------------------------------------------------------------------- Joe Greco - Systems Administrator jgreco@ns.sol.net Solaria Public Access UNIX - Milwaukee, WI 414/342-4847
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702192305.RAA08083>