[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [PATCH] Correct passing of DPKG_ADMINDIR to maintainer scripts with --root



On Tue, Mar 01, 2011 at 05:11:05PM -0600, Jonathan Nieder wrote:
> Hi Steve,

> Steve Langasek wrote:

> > --- a/src/help.c
> > +++ b/src/help.c
> > @@ -186,6 +186,11 @@ preexecscript(struct command *cmd)
> >    size_t instdirl;
> >  
> >    if (*instdir) {
> > +    if (strstr(admindir, instdir) == admindir)
> > +      /* Already forked, safe to modify the environment; strip off the chroot
> > +         path from our admin dir so this works under the chroot */
> > +      if (setenv("DPKG_ADMINDIR", admindir+strlen(instdir), 1) < 0)
> > +        ohshite(_("unable to setenv for subprocesses"));

> strstr can be slow. :)  Why not:

> 	size_t instdirlen = strlen(instdir);
> 	if (strncmp(admindir, instdir, instdirlen) == 0) {
> 	  /* ... explanatory comment ... */
> 	  if (setenv("DPKG_ADMINDIR", admindir + instdirlen, 1) < 0)
> 	    ohshite(_(...));
> 	}

Agreed, that's better.  strstr was just the closest hammer I had to hand
when trying to unbreak this quickly. :)

-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slangasek@ubuntu.com                                     vorlon@debian.org

Attachment: signature.asc
Description: Digital signature


Reply to: