[Buildroot] Buildroot fails on powerpc with busybox login.c

Rich Felker dalias at aerifal.cx
Mon Sep 18 07:12:25 UTC 2006


On Mon, Sep 18, 2006 at 07:44:01AM +0200, Denis Vlasenko wrote:
> > > But here it is used in a function, not in a <applet>_main().
> > > The function has no way to check whether caller uses bb_common_bufsiz1
> > > in an unsafe manner (i.e. across the call to this function).
> > > 
> > > So it is a bit scary here. And it gives no size savings AT ALL
> > > because char buf[BUFSIZ] was an automatic variable on stack.
> > 
> > Declaring 4k on the stack is a bit impolite to nommu systems.
> 
> In this particular case buffer is used for reading lines from /etc/securetty.
> I think it can be reduced to 128 bytes. If someone got bigger line there,
> they'll get what they asked for.

There are WAAAY too many places where BB is using BUFSIZ as a generic
"we hope it's big enough for whatever we need" buffer. I found several
uses in the vi applet that were doing memset-0 on the whole buffer
every time you move the cursor. The _only_ meaning of BUFSIZ is to
tell you what size buffer you should pass to the (obsolete, replaced
by setvbuf) setbuf stdio function.

> > > > login.02_of_03.diff
> > > > shrink by perusing bb_getopt_ulflags()
> > > 
> > > +#define LOGIN_OPT_f (1<<0)
> > > +#define LOGIN_OPT_h (1<<1)
> > > +#define LOGIN_OPT_p (1<<2)
> > > 
> > > Defining constants using enum {...}; is saner.
> > 
> > Why?  (I've never understood this one.  O_RDWR and O_BINARY were #defines back 
> > in the 1970's, what exactly's wrong with it?)
> 
> In 1970's there were no enums in C, iirc. I think this is the sole reason.

#defines can also be used by the preprocessor in #if conditionals and
such. You can't do that with enum afaik.

In particular, #ifdef O_RDWR and similar are useful to make sure the
header defined the symbolic constants you expected it to define. And
please no don't suggest we do the horrible unreadable GNUism of
interleaving like ..
enum {
  a=0,
#define a a
  b=1,
#define b b
...
}

Rich




More information about the busybox mailing list