From: Martin Stiborsky Date: Mon, 5 Jan 2015 21:54:32 +0000 (+0100) Subject: null check for getpwuid and pw_name X-Git-Tag: 2.7~12^2~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6ffe86ca12c0a1b532532284aebe4ce417323cdb;p=i3%2Fi3lock null check for getpwuid and pw_name --- diff --git a/i3lock.c b/i3lock.c index bead884..4f9d5d4 100644 --- a/i3lock.c +++ b/i3lock.c @@ -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) {