]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: don't ignore sscanf() return code [coverity scan]
authorKarel Zak <kzak@redhat.com>
Mon, 29 Nov 2021 14:30:10 +0000 (15:30 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 29 Nov 2021 14:30:10 +0000 (15:30 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/hwclock.c

index ff148f62acce38fc045f04b4a84b8d02d90c3b13..af8ac0860ce28277aa9de3668d894c6d4df11efc 100644 (file)
@@ -251,15 +251,17 @@ static int read_adjtime(const struct hwclock_control *ctl,
 
        fclose(adjfile);
 
-       sscanf(line1, "%lf %"SCNd64" %lf",
-               &adjtime_p->drift_factor,
-               &last_adj_time,
-               &adjtime_p->not_adjusted);
+       if (sscanf(line1, "%lf %"SCNd64" %lf",
+                       &adjtime_p->drift_factor,
+                       &last_adj_time,
+                       &adjtime_p->not_adjusted) != 3)
+               warnx(_("Warning: unrecognized line in adjtime file: %s"), line1);
 
-       sscanf(line2, "%"SCNd64, &last_calib_time);
+       if (sscanf(line2, "%"SCNd64, &last_calib_time) != 1)
+               warnx(_("Warning: unrecognized line in adjtime file: %s"), line2);
 
-    adjtime_p->last_adj_time = (time_t)last_adj_time;
-    adjtime_p->last_calib_time = (time_t)last_calib_time;
+       adjtime_p->last_adj_time = (time_t)last_adj_time;
+       adjtime_p->last_calib_time = (time_t)last_calib_time;
 
        if (!strcmp(line3, "UTC\n")) {
                adjtime_p->local_utc = UTC;