[PATCH RESEND] clean up bb_pwd.c

Tito farmatito at tiscali.it
Wed Dec 3 07:50:11 UTC 2008


On Tuesday 02 December 2008 23:57:34 you wrote:
> On Monday 24 November 2008 14:48, Tito wrote:
> > Hi Denys,
> > Just a remainder, is there any interest in these patches or should 
> > i drop them.
> 
> In passwd_main():
> 
>         /* Will complain and die if username not found */
> -       myname = xstrdup(bb_getpwuid(NULL, -1, myuid));
> +       myname = xuid2uname(myuid);
>         name = argv[0] ? argv[0] : myname;
>  
>         pw = getpwnam(name);
> 
> This is dangerous. You depend on that static storage
> not being trashed. But it likely will be, in the getpwnam()
> call two lines below! You also did not remove this:
> 
> if (ENABLE_FEATURE_CLEAN_UP) free(myname);

Ops, how could i be so blind.......

> 
> 
> 
> 
> static char* get_cached(cache_t *cp, unsigned id,
>                         char* FAST_FUNC x2x_utoa(unsigned id))
> {
> ...
> const char* FAST_FUNC get_cached_username(uid_t uid)
> {
>         return get_cached(&username, uid, uid2uname_utoa);
> }
> const char* FAST_FUNC get_cached_groupname(gid_t gid)
> {
>         return get_cached(&groupname, gid, gid2group_utoa);
> }
> 
> You are lucky that C does not check prototypes strictly enough.
> But in fact you have a mismatch: uid2uname_utoa takes uid_t,
> not unsigned. And if they have different size?...
> 
> 
> I fixed these up and applied the patchset. Thanks.
> --
> vda
>

Thanks for your time,
Ciao,
Tito

PS: I will send in a patch for the getpwnam stuff as soon as I have some spare time.
      Most of the work is already done.





More information about the busybox mailing list