Since we can feed localtime(3) with garbage input, or with input it cannot
authormestre <mestre@openbsd.org>
Mon, 20 Aug 2018 06:24:50 +0000 (06:24 +0000)
committermestre <mestre@openbsd.org>
Mon, 20 Aug 2018 06:24:50 +0000 (06:24 +0000)
interpret, we always need to check its return value, and in the case it's NULL
then error and exit before proceeding further otherwise in this specific
program we would find a null dereference down the road which would make the
program segfault.

OK cheloha@

usr.sbin/ac/ac.c

index 97d0f82..f0005ce 100644 (file)
@@ -410,6 +410,8 @@ ac(FILE     *fp)
                prev = usr.ut_time;
                if (Flags & AC_D) {
                        ltm = localtime(&usr.ut_time);
+                       if (ltm == NULL)
+                               err(1, "localtime");
                        if (day >= 0 && day != ltm->tm_yday) {
                                day = ltm->tm_yday;
                                /*
@@ -461,6 +463,8 @@ ac(FILE     *fp)
 
        if (Flags & AC_D) {
                ltm = localtime(&usr.ut_time);
+               if (ltm == NULL)
+                       err(1, "localtime");
                if (day >= 0 && day != ltm->tm_yday) {
                        /*
                         * print yesterday's total