Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Jan 2011 20:50:54 -0800
From:      "Jordan K. Hubbard" <jkh@turbofuzz.com>
To:        Eitan Adler <lists@eitanadler.com>
Cc:        joe@freebsd.org, jkh@freebsd.org, hackers@freebsd.org, phk@freebsd.org
Subject:   Re: [patch] should crunchgen use basename(3) instead of homebrew code?
Message-ID:  <6DCC53BA-D20A-4593-B3B0-1389734AD308@turbofuzz.com>
In-Reply-To: <AANLkTimyXvm%2B6zyAobzxq-PCfBJus2ZMHvk5ztBOzufW@mail.gmail.com>
References:  <AANLkTimyXvm%2B6zyAobzxq-PCfBJus2ZMHvk5ztBOzufW@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail-296-42958711
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

Wow.  A couple of questions.

1. Is it really worth messing with code as old as crunchgen(1) at all?  =
Seriously.  What's there isn't exactly "broken", and it seems like =
needlessly walking into a vampire's crypt without so much as a stake or =
clove of garlic on your person.  Only something bad can happen.

2. basename(3) also strips trailing '/' characters, which the code you =
are replacing does not.  Does this actually matter?  Hell if I know, I =
haven't looked at the inputs to that code in ages and I have enough =
common sense to stay out of musty crypts, so I'm not going to look, =
either. :)

- Jordan

On Jan 1, 2011, at 11:37 PM, Eitan Adler wrote:

> I'm not sure about this patch because of the behavior change of
> -    slash =3D strrchr(path, '/');
> -    basename =3D slash? slash+1 : path;
> +    bn =3D basename(slash);
>=20
> CCed to the last few people to touch the relevant code (via svn =
praise)
>=20
> Index: crunched_main.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> --- crunched_main.c	(revision 216884)
> +++ crunched_main.c	(working copy)
> @@ -33,6 +33,7 @@
>  *	or calls one of them based on argv[1].   This allows the testing =
of
>  *	the crunched binary without creating all the links.
>  */
> +#include <libgen.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> @@ -47,22 +48,21 @@
>=20
> int main(int argc, char **argv, char **envp)
> {
> -    char *slash, *basename;
> +    char *slash, *bn;
>     struct stub *ep;
>=20
>     if(argv[0] =3D=3D NULL || *argv[0] =3D=3D '\0')
> 	crunched_usage();
>=20
> -    slash =3D strrchr(argv[0], '/');
> -    basename =3D slash? slash+1 : argv[0];
> +    bn =3D basename(argv[0]);
>=20
>     for(ep=3Dentry_points; ep->name !=3D NULL; ep++)
> -	if(!strcmp(basename, ep->name)) break;
> +	if(!strcmp(bn, ep->name)) break;
>=20
>     if(ep->name)
> 	return ep->f(argc, argv, envp);
>     else {
> -	fprintf(stderr, "%s: %s not compiled in\n", EXECNAME, basename);
> +	fprintf(stderr, "%s: %s not compiled in\n", EXECNAME, bn);
> 	crunched_usage();
>     }
> }
> @@ -70,14 +70,13 @@
>=20
> int crunched_here(char *path)
> {
> -    char *slash, *basename;
> +    char *slash, *bn;
>     struct stub *ep;
>=20
> -    slash =3D strrchr(path, '/');
> -    basename =3D slash? slash+1 : path;
> +    bn =3D basename(slash);
>=20
>     for(ep=3Dentry_points; ep->name !=3D NULL; ep++)
> -	if(!strcmp(basename, ep->name))
> +	if(!strcmp(bn, ep->name))
> 	    return 1;
>     return 0;
> }
>=20
>=20
> --=20
> Eitan Adler


--Apple-Mail-296-42958711--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6DCC53BA-D20A-4593-B3B0-1389734AD308>