From 12800a81645bb32b13c3d4cee47945b2752500c5 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 18 Aug 2012 21:12:02 -0500 Subject: 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. --- toys/ls.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/toys/ls.c b/toys/ls.c index 561b3534..1881df71 100644 --- a/toys/ls.c +++ b/toys/ls.c @@ -88,6 +88,9 @@ DEFINE_GLOBALS( 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 endtype(struct stat *st) 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 @@ static void listfiles(int dirfd, struct dirtree *indir) 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 @@ static void listfiles(int dirfd, struct dirtree *indir) 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); } -- cgit v1.2.3