[BusyBox] ash lockup when reading /etc/profile

Adam Slattery aslattery at sunriselinux.com
Fri Jul 13 20:39:26 UTC 2001


I have ash compiled with command editing.

When invoked as "sh" it works fine because it doesn't read /etc/profile.
You can lock it by doing `argv0 _install/bin/sh -sh` with either
/etc/profile or .profile existing (they can be empty).

I've hacked around for about an hour trying to track this down and I
finally found a place to work around this.


The problem is in ash.c in preadfd():

#ifdef BB_FEATURE_COMMAND_EDITING
        {
            if (!iflag)
                    nr = safe_read(parsefile->fd, buf, BUFSIZ - 1);
            else {
                    cmdedit_read_input((char*)cmdedit_prompt, buf);
                    nr = strlen(buf);
            }
        }
#else

When reading a profile file, iflag is 1, so cmdedit_read_input() is used.
I'm not very familiar with the internals of the shells in busybox
(especially with Vladimir's latest changes), but it would seem
cmdedit_read_input() is not meant to be used with reading files.

I've done a fair amount of testing (not extensive, but i've looked at a
few differant things), and the profile reading in ash seems to be the only
thing that's broken.

Here is the patch I've come up with. It seems to work, but Erik/Vladimir
might want to fix this problem in a differant place in the code.


- Adam Slattery



--- ash.c.old       Thu Jul 12 20:26:31 2001
+++ ash.c   Fri Jul 13 17:17:40 2001
@@ -7870,6 +7872,7 @@
        int fd;
        int xflag_set = 0;
        int vflag_set = 0;
+       int saved_iflag;

        INTOFF;
        if ((fd = open(name, O_RDONLY)) >= 0)
@@ -7884,7 +7887,12 @@
            if (vflag)
                    vflag = 0, vflag_set = 1;
        }
+
+       saved_iflag = iflag;
+       iflag = 0;
        cmdloop(0);
+       iflag = saved_iflag;
+
        if (qflag)  {
            if (xflag_set)
                    xflag = 1;







More information about the busybox mailing list