From owner-freebsd-audit Sun Aug 12 14:12:23 2001 Delivered-To: freebsd-audit@freebsd.org Received: from mail.musha.org (daemon.musha.org [61.122.44.178]) by hub.freebsd.org (Postfix) with ESMTP id 5DB5037B405; Sun, 12 Aug 2001 14:12:17 -0700 (PDT) (envelope-from knu@iDaemons.org) Received: from archon.local.idaemons.org (archon.local.idaemons.org [192.168.1.32]) by mail.musha.org (Postfix) with ESMTP id A8BD94D833; Mon, 13 Aug 2001 06:12:15 +0900 (JST) Date: Mon, 13 Aug 2001 06:12:15 +0900 Message-ID: <86ofpl0yq8.wl@archon.local.idaemons.org> From: "Akinori MUSHA" To: Mike Barcroft , audit@FreeBSD.org Subject: Re: adding -P option to pkg_delete(1) In-Reply-To: <20010812164843.A29363@coffee.q9media.com> References: <86elqphctp.wl@archon.local.idaemons.org> <86d761hijs.wl@archon.local.idaemons.org> <20010812140750.B29132@coffee.q9media.com> <86snex15o4.wl@archon.local.idaemons.org> <20010812164843.A29363@coffee.q9media.com> User-Agent: Wanderlust/2.7.1 (Too Funky) SEMI/1.14.3 (Ushinoya) FLIM/1.14.3 (=?ISO-8859-1?Q?Unebigory=F2mae?=) APEL/10.3 MULE XEmacs/21.1 (patch 14) (Cuyahoga Valley) (i386--freebsd) Organization: Associated I. Daemons X-PGP-Public-Key: finger knu@FreeBSD.org X-PGP-Fingerprint: 081D 099C 1705 861D 4B70 B04A 920B EFC7 9FD9 E1EE MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG At Sun, 12 Aug 2001 16:48:43 -0400, Mike Barcroft wrote: > > On Mon, Aug 13, 2001 at 03:42:19AM +0900, Akinori MUSHA wrote: > > > This could probably be written better, so that you don't have to walk > > > filename so many times. > > > > Yes, alternatively you could write it as follows, for example: > > > > /* [^\/]\.so(\.\d+)*$ */ > > static Boolean > > is_shlib(char *filename) > > { > > char *p; > > > > p = strrchr(filename, 's'); > > > > if (p == NULL || p[1] != 'o' || > > p - filename < 2 || p[-1] != '.' || p[-2] == '/') > > return FALSE; > > > > p += 2; > > > > /* skip version numbers */ > > while (*p) { > > if (*p != '.' || !isdigit(*++p)) > > return FALSE; > > while (isdigit(*++p)) > > ; > > } > > > > return TRUE; > > } > > > > (But I don't like this ;) > > Neither do I. Mostly because you could be accessing memory before > filename starts. No, no. If (p - filename < 2) is false, the rest is not evaluated. It would be more than just "don't like" if the code had such a terrible flaw. ;) The reason why I don't like it is because it goes to extremes for performance, to result in less readable, inflexible code. > I was thinking more along the lines of: > > /* > * Returns TRUE if filename matches /\.so$/ or /\.so\.\d+$/, otherwise FALSE. > */ > static Boolean > is_shlib(const char *filename) > { > int digit; > char *p; > > digit = 0; > p = (char *)filename + strlen(filename); > while (--p > filename && isdigit(*p)) > digit = 1; > if (p - 1 <= filename) > return FALSE; > if (digit && *p == '.') > p--; > if (p - 2 > filename && strncmp(p - 2, ".so", 3) == 0) > return TRUE; > else > return FALSE; > } I found some problems with it: - Note that the . part may repeat, not to mention Linux shared libraries. - is_shlib("foo/.so") will return TRUE, which can't be a shared library but aa dotfile. - is_shlib("foo.so4") will return TRUE, which probably isn't a shared library. I'll try more later. Thanks for sharing the work with me. :) -- / /__ __ Akinori.org / MUSHA.org / ) ) ) ) / FreeBSD.org / Ruby-lang.org Akinori MUSHA aka / (_ / ( (__( @ iDaemons.org / and.or.jp "Freeze this moment a little bit longer, make each impression a little bit stronger.. Experience slips away -- Time stand still" To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message