From owner-freebsd-hackers Wed Feb 19 15:10:05 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id PAA25210 for hackers-outgoing; Wed, 19 Feb 1997 15:10:05 -0800 (PST) Received: from anacreon.sol.net (anacreon.sol.net [206.55.64.116]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id PAA24951; Wed, 19 Feb 1997 15:05:44 -0800 (PST) Received: from solaria.sol.net (solaria.sol.net [206.55.65.75]) by anacreon.sol.net (8.8.5/8.6.12) with SMTP id RAA12700; Wed, 19 Feb 1997 17:05:33 -0600 (CST) Received: from localhost by solaria.sol.net (8.5/8.5) id RAA08083; Wed, 19 Feb 1997 17:05:31 -0600 From: Joe Greco Message-Id: <199702192305.RAA08083@solaria.sol.net> Subject: Re: hmm To: guido@gvr.win.tue.nl (Guido van Rooij) Date: Wed, 19 Feb 97 17:05:29 CST Cc: top@sonic.cris.net, audit-bin@freebsd.org, FreeBSD-hackers@freebsd.org In-Reply-To: <199702192053.VAA02956@gvr.win.tue.nl> from "Guido van Rooij" at Feb 19, 97 09:53:45 pm X-Mailer: ELM [version 2.4dev PL65] MIME-Version: 1.0 Content-Type: text Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > > 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