tar: Don't crash when get{pw,gr}uid fails

This commit is contained in:
Michael Forney 2014-11-01 20:36:37 +00:00 committed by sin
parent 73115682ed
commit 453ce96d44

4
tar.c
View File

@ -177,8 +177,8 @@ archive(const char* path)
putoctal(h->mtime, (unsigned)st.st_mtime, sizeof h->mtime); putoctal(h->mtime, (unsigned)st.st_mtime, sizeof h->mtime);
memcpy(h->magic, "ustar", sizeof h->magic); memcpy(h->magic, "ustar", sizeof h->magic);
memcpy(h->version, "00", sizeof h->version); memcpy(h->version, "00", sizeof h->version);
snprintf(h->uname, sizeof h->uname, "%s", pw->pw_name); snprintf(h->uname, sizeof h->uname, "%s", pw ? pw->pw_name : "");
snprintf(h->gname, sizeof h->gname, "%s", gr->gr_name); snprintf(h->gname, sizeof h->gname, "%s", gr ? gr->gr_name : "");
mode = st.st_mode; mode = st.st_mode;
if(S_ISREG(mode)) { if(S_ISREG(mode)) {