aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Hastings <abh@cray.com>2011-01-27 11:43:45 -0600
committerEric B Munson <emunson@mgebm.net>2011-02-23 11:55:34 -0500
commit48b7ff1d536f63025e6b279be6798d167a4fa87a (patch)
tree0146627e82c9afe62bcc3b4b45ff24c19d6d829c
parent1fb91f1092771a5ae91179ef5b5a9174b3222c69 (diff)
downloadlibhugetlbfs-48b7ff1d536f63025e6b279be6798d167a4fa87a.tar.gz
hugeadm.c: Don't segfault if user not in passwd file
If a user somehow managed to run hugeadm without an entry being present for the user in the passwd file, hugeadm was segfaulting because it did not check for failure of getpwuid(). Fix: check for getpwuid() failure and issue an appropriate error message. Based on a patch originally authored by Dean Luick <luick@cray.com>. Signed-off-by: Andrew Hastings <abh@cray.com> on behalf of Cray Inc. Signed-off-by: Eric B Munson <emunson@mgebm.net>
-rw-r--r--hugeadm.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/hugeadm.c b/hugeadm.c
index fe5f89f..509968a 100644
--- a/hugeadm.c
+++ b/hugeadm.c
@@ -860,6 +860,13 @@ void check_user(void)
uid = getuid();
pwd = getpwuid(uid);
+ /* Don't segfault if user does not have a passwd entry. */
+ if (!pwd) {
+ printf("\n");
+ WARNING("User uid %d is not in the password file!\n", uid);
+ return;
+ }
+
if (gid != pwd->pw_gid && !user_in_group(grp->gr_mem, pwd->pw_name) && uid != 0) {
printf("\n");
WARNING("User %s (uid: %d) is not a member of the hugetlb_shm_group %s (gid: %d)!\n", pwd->pw_name, uid, grp->gr_name, gid);