[PATCH RESEND] clean up bb_pwd.c

Denys Vlasenko vda.linux at googlemail.com
Tue Dec 2 22:57:34 UTC 2008


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);





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



More information about the busybox mailing list