# HG changeset patch # User Rob Landley # Date 1345342322 18000 # Node ID dd82e0b28eda0697438d43a9f4f35278d3af757a # Parent 2364ace48ab121cdc377f2575064663f59e5b5a9 Fix bug spotted by Avery Pennarun: getusername() and getgroupname() can reuse the utoa buffer when neither is recognized, meaning uid would be shown again instead of gid. diff -r 2364ace48ab1 -r dd82e0b28eda toys/ls.c --- a/toys/ls.c Thu Aug 16 22:24:30 2012 -0500 +++ b/toys/ls.c Sat Aug 18 21:12:02 2012 -0500 @@ -88,6 +88,9 @@ unsigned screen_width; int nl_title; + + // group and user can make overlapping use of the utoa() buf, so move it + char uid_buf[12]; ) #define TT this.ls @@ -121,7 +124,8 @@ static char *getusername(uid_t uid) { struct passwd *pw = getpwuid(uid); - return pw ? pw->pw_name : utoa(uid); + utoa_to_buf(uid, TT.uid_buf, 12); + return pw ? pw->pw_name : TT.uid_buf; } static char *getgroupname(gid_t gid) @@ -365,7 +369,7 @@ if (flags & (FLAG_l|FLAG_o|FLAG_n|FLAG_g)) { struct tm *tm; - char perm[11], thyme[64], c, d, *usr, *upad, buf[12], *grp, *grpad; + char perm[11], thyme[64], c, d, *usr, *upad, *grp, *grpad; int i, bit; perm[10]=0; @@ -402,8 +406,8 @@ else { upad = toybuf+255-(totals[3]-len[3]); if (flags&FLAG_n) { - usr = buf; - utoa_to_buf(st->st_uid, buf, 12); + usr = TT.uid_buf; + utoa_to_buf(st->st_uid, TT.uid_buf, 12); } else usr = getusername(st->st_uid); }