null check for getpwuid and pw_name

pull/3/head
Martin Stiborsky 2015-01-05 22:54:32 +01:00
parent 7d52029ae3
commit 6ffe86ca12
1 changed files with 5 additions and 2 deletions

View File

@ -661,7 +661,8 @@ static void raise_loop(xcb_window_t window) {
}
int main(int argc, char *argv[]) {
char *username = getpwuid(getuid())->pw_name;
struct passwd *pw = getpwuid(getuid());
char *username;
char *image_path = NULL;
int ret;
struct pam_conv conv = {conv_callback, NULL};
@ -686,8 +687,10 @@ int main(int argc, char *argv[]) {
{NULL, no_argument, NULL, 0}
};
if (username == NULL)
if (pw == NULL)
err(EXIT_FAILURE, "getpwuid() failed");
if ((username = pw->pw_name) == NULL)
errx(EXIT_FAILURE, "pw->pw_name is NULL.\n");
char *optstring = "hvnbdc:p:ui:teI:f";
while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {