From f6d3d525bf2c0afa0190e767f6de575cdbd5bcfd Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Fri, 7 Aug 2009 19:28:31 -0700 Subject: [PATCH] Fix a segfault-causing bug when converting a numeric group to a name fails. The original code had a copy-and-paste bug when converting a numeric group id into a symbolic group name: rather than checking that getgrgid returned a valid result, it checked the result of getpwuid. If any files in the backup snapshot belonged to a non-existent group, this resulted in a segfault. Problem found and patch provided by Chris Wilson . --- scandir.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scandir.cc b/scandir.cc index d775219..f902fa0 100644 --- a/scandir.cc +++ b/scandir.cc @@ -357,12 +357,12 @@ void dump_inode(const string& path, // Path within snapshot file_info["volatile"] = "1"; struct passwd *pwd = getpwuid(stat_buf.st_uid); - if (pwd != NULL) { + if (pwd != NULL && pwd->pw_name != NULL) { file_info["user"] += " (" + uri_encode(pwd->pw_name) + ")"; } struct group *grp = getgrgid(stat_buf.st_gid); - if (pwd != NULL) { + if (grp != NULL && grp->gr_name != NULL) { file_info["group"] += " (" + uri_encode(grp->gr_name) + ")"; } -- 2.20.1