changeset 72:46f39359c4a7

arogue5: avoid segfaulting if getpwuid() fails.
author elwin
date Sat, 11 Aug 2012 23:45:34 +0000
parents d8e5c5dd9b55
children 3192c1e03970
files arogue5/main.c arogue5/mdport.c
diffstat 2 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/arogue5/main.c	Sat Aug 11 21:58:20 2012 +0000
+++ b/arogue5/main.c	Sat Aug 11 23:45:34 2012 +0000
@@ -49,14 +49,14 @@
     register char *env;
     int lowtime;
     time_t now;
-    char *roguedir = md_getroguedir();
+    char *roguedir;
 
+    roguedir = md_getroguedir();
     md_init();
 
     /*
      * get home and options from environment
      */
-
     strncpy(home,md_gethomedir(),LINELEN);
 
 #ifdef SAVEDIR
--- a/arogue5/mdport.c	Sat Aug 11 21:58:20 2012 +0000
+++ b/arogue5/mdport.c	Sat Aug 11 23:45:34 2012 +0000
@@ -234,7 +234,10 @@
 
     pw = getpwuid(getuid());
 
-    l = pw->pw_name;
+    if (pw != NULL)
+        l = pw->pw_name;
+    else
+        l = "";
 #endif
 
     if ((l == NULL) || (*l == '\0'))
@@ -265,7 +268,10 @@
     struct passwd *pw;
     pw = getpwuid(getuid());
 
-    h = pw->pw_dir;
+    if (pw != NULL)
+        h = pw->pw_dir;
+    else
+        h = "";
 
     if (strcmp(h,"/") == 0)
         h = NULL;
@@ -325,7 +331,10 @@
     char *def = "/bin/sh";
     struct passwd *pw;
     pw = getpwuid(getuid());
-    s = pw->pw_shell;
+    if (pw != NULL)
+        s = pw->pw_shell;
+    else
+        s = "";
 #endif
     if ((s == NULL) || (*s == '\0'))
         if ( (s = getenv("COMSPEC")) == NULL)