From 06fc4c9dd220fd3a30adce4ef639efd50186cdf8 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Sat, 19 Apr 2008 17:55:32 +0000 Subject: [PATCH] - handle failure of getpwuid() more gracefully [r19335] --- ir/libcore/lc_opts.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ir/libcore/lc_opts.c b/ir/libcore/lc_opts.c index ff472c690..757dde8a0 100644 --- a/ir/libcore/lc_opts.c +++ b/ir/libcore/lc_opts.c @@ -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)); - /* .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)); + /* .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)); -- 2.20.1