]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Improve scanning data/time, fixes bug #2472
authorKern Sibbald <kern@sibbald.com>
Sun, 10 May 2020 15:46:46 +0000 (17:46 +0200)
committerKern Sibbald <kern@sibbald.com>
Sun, 10 May 2020 15:46:46 +0000 (17:46 +0200)
bacula/src/lib/btime.c

index 3f0f548e345153249536a7aaed599be89467101f..3d6e29db83ff22718546f4659097181df61515e4 100644 (file)
@@ -128,13 +128,15 @@ utime_t str_to_utime(char *str)
    struct tm tm;
    time_t time;
 
-   /* Check for bad argument */
-   if (!str || *str == 0) {
+   /* Minimal check for bad argument */
+   if (!str || *str == 0 || (strlen(str) != 19) ||
+       (str[4] != '-') || (str[7] != '-') ||
+       (str[13] != ':') || (str[16] != ':')) {
       return 0;
    }
 
-   if (sscanf(str, "%d-%d-%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
-                                        &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
+   if (sscanf(str, "%d-%d-%d %d:%d:%d", &tm.tm_year,
+       &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
       return 0;
    }
    if (tm.tm_mon > 0) {