]> git.sesse.net Git - vlc/commitdiff
Do not assume sysconf() returns a positive value
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 13 Aug 2012 19:17:32 +0000 (22:17 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 13 Aug 2012 19:19:03 +0000 (22:19 +0300)
src/posix/dirs.c

index 7c6756642c15def7bfa837149e5763f726d49411..0fd5991eedd4c88f7b99b0b5bcc329416831a381 100644 (file)
@@ -72,22 +72,22 @@ static char *config_GetHomeDir (void)
 {
     /* 1/ Try $HOME  */
     const char *home = getenv ("HOME");
+    if (home != NULL)
+        return strdup (home);
 #if defined(HAVE_GETPWUID_R)
     /* 2/ Try /etc/passwd */
-    char buf[sysconf (_SC_GETPW_R_SIZE_MAX)];
-    if (home == NULL)
+    long max = sysconf (_SC_GETPW_R_SIZE_MAX);
+    if (max != -1)
     {
-        struct passwd pw, *res;
+        char buf[max];
+        struct passwd pwbuf, *pw;
 
-        if (!getpwuid_r (getuid (), &pw, buf, sizeof (buf), &res) && res)
-            home = pw.pw_dir;
+        if (getpwuid_r (getuid (), &pwbuf, buf, sizeof (buf), &pw) == 0
+          && pw != NULL)
+            return strdup (pw->pw_dir);
     }
 #endif
-
-    if (!home)
-        return NULL;
-
-    return strdup (home);
+    return NULL;
 }
 
 static char *config_GetAppDir (const char *xdg_name, const char *xdg_default)