getpwuid checking



This patch fixes two potential segfault bugs because the result of
getpwuid is not checked.

Regards,

Oskar Liljeblad (oskar osk mine nu)

diff -u -p src/main.c.v0 src/main.c
--- src/main.c.v0	2004-09-23 08:41:22.000000000 +0200
+++ src/main.c	2004-09-23 09:09:12.000000000 +0200
@@ -1761,8 +1761,12 @@ OS_Setup (void)
 {
     char *mc_libdir;
     shell = getenv ("SHELL");
-    if (!shell || !*shell)
-	shell = g_strdup (getpwuid (geteuid ())->pw_shell);
+    if (!shell || !*shell) {
+        struct passwd *pwd;
+        pwd = getpwuid (geteuid ());
+        if (pwd != NULL)
+           shell = g_strdup (pwd->pw_shell);
+    }
     if (!shell || !*shell)
 	shell = "/bin/sh";
 
diff -u -p src/utilunix.c.v0 src/utilunix.c
--- src/utilunix.c.v0	2004-09-23 08:36:08.000000000 +0200
+++ src/utilunix.c	2004-09-23 09:05:28.000000000 +0200
@@ -323,8 +323,13 @@ mc_tmpdir (void)
     }
 
     pwd = getpwuid (getuid ());
-    g_snprintf (buffer, sizeof (buffer), "%s/mc-%s", sys_tmp,
-		pwd->pw_name);
+    if (pwd == NULL) {
+        g_snprintf (buffer, sizeof (buffer), "%s/mc-%d", sys_tmp,
+		    getuid ());
+    } else {
+        g_snprintf (buffer, sizeof (buffer), "%s/mc-%s", sys_tmp,
+		    pwd->pw_name);
+    }
     canonicalize_pathname (buffer);
 
     if (lstat (buffer, &st) == 0) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]