Date: Mon, 13 Aug 2001 06:12:15 +0900 From: "Akinori MUSHA" <knu@iDaemons.org> To: Mike Barcroft <mike@FreeBSD.org>, audit@FreeBSD.org Subject: Re: adding -P option to pkg_delete(1) Message-ID: <86ofpl0yq8.wl@archon.local.idaemons.org> 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>
index | next in thread | previous in thread | raw e-mail
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 .<num> 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
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86ofpl0yq8.wl>
