Hi,

The following patch makes chpass(1) fail even faster when
the wrong options are provided and usage() would be printed.
In other words, no point accessing environment variables
before checking result of getopt().

- Michael


Index: chpass.c
===================================================================
RCS file: /cvs/src/usr.bin/chpass/chpass.c,v
retrieving revision 1.43
diff -u -p -u -r1.43 chpass.c
--- chpass.c    26 Nov 2015 19:01:47 -0000      1.43
+++ chpass.c    31 Mar 2017 08:03:37 -0000
@@ -66,13 +66,6 @@ main(int argc, char *argv[])
        char *tz, *arg = NULL;
        sigset_t fullset;
 
-       /* We need to use the system timezone for date conversions. */
-       if ((tz = getenv("TZ")) != NULL) {
-           unsetenv("TZ");
-           tzset();
-           setenv("TZ", tz, 1);
-       }
-
        op = EDITENTRY;
        while ((ch = getopt(argc, argv, "a:s:")) != -1)
                switch(ch) {
@@ -90,6 +83,13 @@ main(int argc, char *argv[])
                }
        argc -= optind;
        argv += optind;
+
+       /* We need to use the system timezone for date conversions. */
+       if ((tz = getenv("TZ")) != NULL) {
+           unsetenv("TZ");
+           tzset();
+           setenv("TZ", tz, 1);
+       }
 
        uid = getuid();
 

Reply via email to