]> granicus.if.org Git - linux-pam/commitdiff
pam_securetty: check return value of fgets
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 19 Nov 2013 14:18:44 +0000 (14:18 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 20 Nov 2013 10:52:04 +0000 (10:52 +0000)
Checking return value of fgets not only silences the warning from glibc
but also leads to a cleaner code.

* modules/pam_securetty/pam_securetty.c (securetty_perform_check):
Check return value of fgets.

modules/pam_securetty/pam_securetty.c

index 5f2d1bec32c98fe8e3cbf437aec105d8b28dcfc9..047413093da55e2eceeac1f4b2d293091d7bc460 100644 (file)
@@ -159,11 +159,10 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl,
         if (cmdlinefile != NULL) {
             char line[LINE_MAX], *p;
 
-            line[0] = 0;
-            fgets(line, sizeof(line), cmdlinefile);
+            p = fgets(line, sizeof(line), cmdlinefile);
             fclose(cmdlinefile);
 
-            for (p = line; p; p = strstr(p+1, "console=")) {
+            for (; p; p = strstr(p+1, "console=")) {
                 char *e;
 
                 /* Test whether this is a beginning of a word? */