[PATCH] minor size optimization for dd.c

Denis Vlasenko vda at ilport.com.ua
Mon Mar 20 06:38:10 UTC 2006


On Monday 20 March 2006 05:09, Rob Landley wrote:
> On Sunday 19 March 2006 9:08 pm, Rob Landley wrote:
> 
> > > >See at http://195.66.192.167/linux/bbox/bb_xopen3.patch
> > >
> > > landley disliked this the bb_xopen3 idea, iirc.
> > >
> > > Rob, care to elaborate on why you don't want it, please?
> >
> > More I decided it wasn't something to worry about for 1.1.1 and I put it in
> > my "to revisit" pile.
> 
> While dusting off Tito's rewrite of passwd.c in an attempt to get passwd using 
> salt for 1.1.1, I see this:
> 
>     if ((out_fp = bb_wfopen(dest, "w"))
>         && chmod(dest, ENABLE_FEATURE_SHADOWPASSWDS ? 0600 : 0644) == 0
>         && chown(dest, 0, 0) == 0)
>     {
> 
> And that's a big race condition if wfopen is creating the sucker with 777 and 
> then chmoding it.
>
> So, question about bb_xopen3(): it seems that any use of O_CREAT with 
> bb_xopen() is an error.  Probably we should have debug code that #undefs 
> O_CREAT in libbb.h and #defines O_CREAT to DO_NOT_USE_O_CREAT_WITH_BB_XOPEN, 
> or some such...

The problem is not in the open(). It's in chmod being used instead of fchmod().
fchmod() doesn't have this race.

I've sent a fix for bunzip, gunzip and unlzma which fixes this for these applets.
(http://195.66.192.167/linux/bbox/unlzma_mode_fix_v3.patch)

> Grepping the tree, we do this in a lot of places.  How many of those O_CREAT 
> calls should have O_EXCL with them, but don't?

> For 1.1.1 I'll live with it.  (Although not in passwd.c.)  We need to fix this 
> everywhere for 1.1.2.

--
vda



More information about the busybox mailing list