- handle failure of getpwuid() more gracefully
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 19 Apr 2008 17:55:32 +0000 (17:55 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 19 Apr 2008 17:55:32 +0000 (17:55 +0000)
[r19335]

ir/libcore/lc_opts.c

index ff472c6..757dde8 100644 (file)
@@ -911,11 +911,19 @@ void lc_opts_init(const char *ini_name, lc_opt_entry_t *root, const char *arg_pr
        strncpy(home_dir_ini_file, local_ini_file, sizeof(home_dir_ini_file));
        home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0';
 #else
-       strcpy(path, getpwuid(getuid())->pw_dir);
-       strncat(path, "/", sizeof(path));
-       /* .<cmnt>rc */
-       snprintf(home_dir_ini_file, sizeof(home_dir_ini_file), ".%src", ini_name);
-       home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0';
+       {
+               struct passwd *entry = getpwuid(getuid());
+               if (entry != NULL) {
+                       strcpy(path, entry->pw_dir);
+                       strncat(path, "/", sizeof(path));
+                       /* .<cmnt>rc */
+                       snprintf(home_dir_ini_file, sizeof(home_dir_ini_file), ".%src", ini_name);
+                       home_dir_ini_file[sizeof(home_dir_ini_file) - 1] = '\0';
+               } else {
+                       /* FIXME: some error occured */
+                       home_dir_ini_file[0] = '\0';'
+               }
+       }
 #endif
 
        strncat(path, home_dir_ini_file, sizeof(path));