From 453ce96d44b8bf9de7cccb68dba9d5233d630ea2 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 1 Nov 2014 20:36:37 +0000 Subject: [PATCH] tar: Don't crash when get{pw,gr}uid fails --- tar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tar.c b/tar.c index 4f4abff..c18d89e 100644 --- a/tar.c +++ b/tar.c @@ -177,8 +177,8 @@ archive(const char* path) putoctal(h->mtime, (unsigned)st.st_mtime, sizeof h->mtime); memcpy(h->magic, "ustar", sizeof h->magic); memcpy(h->version, "00", sizeof h->version); - snprintf(h->uname, sizeof h->uname, "%s", pw->pw_name); - snprintf(h->gname, sizeof h->gname, "%s", gr->gr_name); + snprintf(h->uname, sizeof h->uname, "%s", pw ? pw->pw_name : ""); + snprintf(h->gname, sizeof h->gname, "%s", gr ? gr->gr_name : ""); mode = st.st_mode; if(S_ISREG(mode)) {