[dev] [sbase] [PATCH 1/4] tar: Don't crash when get{pw,gr}uid fails

From: Michael Forney <mforney_AT_mforney.org>
Date: Sat, 1 Nov 2014 20:36:37 +0000

---
 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
_AT_@ -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)) {
-- 
2.1.3.1.g339ec9c
Received on Sat Nov 01 2014 - 21:36:37 CET

This archive was generated by hypermail 2.3.0 : Sat Nov 01 2014 - 21:48:08 CET