[hackers] [sbase] touch: make invalid date an error and fix uninitialised value || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Fri, 15 Apr 2016 20:53:06 +0200 (CEST)

commit 8d96afd4fb266688e8f55db978d5bc9b3c380ca6
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
AuthorDate: Fri Apr 15 20:44:32 2016 +0200
Commit: sin <sin_AT_2f30.org>
CommitDate: Fri Apr 15 19:53:01 2016 +0100

    touch: make invalid date an error and fix uninitialised value
    
    reproduce: touch -t 12345678 mytralala
    
    would only give a warning and use uninitialised time values. The proper
    way is to treat it as an error. Clear the "struct tm" and kill some lines
    just in case.

diff --git a/touch.c b/touch.c
index b957fa5..fca2f16 100644
--- a/touch.c
+++ b/touch.c
_AT_@ -48,7 +48,7 @@ touch(const char *file)
 static time_t
 parsetime(char *str, time_t current)
 {
- struct tm *cur, t;
+ struct tm *cur, t = { 0 };
         int zulu = 0;
         char *format;
         size_t len = strlen(str);
_AT_@ -59,12 +59,10 @@ parsetime(char *str, time_t current)
         switch (len) {
         /* -t flag argument */
         case 8:
- t.tm_sec = 0;
                 t.tm_year = cur->tm_year;
                 format = "%m%d%H%M";
                 break;
         case 10:
- t.tm_sec = 0;
                 format = "%y%m%d%H%M";
                 break;
         case 11:
_AT_@ -72,7 +70,6 @@ parsetime(char *str, time_t current)
                 format = "%m%d%H%M.%S";
                 break;
         case 12:
- t.tm_sec = 0;
                 format = "%Y%m%d%H%M";
                 break;
         case 13:
_AT_@ -98,7 +95,7 @@ parsetime(char *str, time_t current)
         }
 
         if (!strptime(str, format, &t))
- weprintf("strptime %s: Invalid date format\n", str);
+ eprintf("strptime %s: Invalid date format\n", str);
         if (zulu) {
                 t.tm_hour += t.tm_gmtoff / 60;
                 t.tm_gmtoff = 0;
Received on Fri Apr 15 2016 - 20:53:06 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 15 2016 - 21:00:16 CEST