commit 453ce96d44b8bf9de7cccb68dba9d5233d630ea2
parent 73115682ede243bdbe5f69779e9fec0dc1698a80
Author: Michael Forney <mforney@mforney.org>
Date: Sat, 1 Nov 2014 20:36:37 +0000
tar: Don't crash when get{pw,gr}uid fails
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git 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)) {