]> 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)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:19 +0000 (10:44 +0200)
bacula/src/lib/btime.c

index 997fae34f102add40f8a7853172628ed4740f0f0..50020483445ebaa42ad2819e484bc7a5b1efc977 100644 (file)
@@ -140,13 +140,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) {