]> sourceware.org Git - lvm2.git/commitdiff
hints: validate sscanf results
authorZdenek Kabelac <zkabelac@redhat.com>
Thu, 14 Nov 2019 16:59:17 +0000 (17:59 +0100)
committerZdenek Kabelac <zkabelac@redhat.com>
Thu, 14 Nov 2019 17:06:42 +0000 (18:06 +0100)
lib/label/hints.c

index ec43dd35c70d651b91b575efd132071a39fdc848..09f12deb6c4c5dbdb954794fdf2bf5b6dd991037 100644 (file)
@@ -716,10 +716,9 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
                keylen = strlen("scan_lvs:");
                if (!strncmp(_hint_line, "scan_lvs:", keylen)) {
                        int scan_lvs = 0;
-                       sscanf(_hint_line + keylen, "%u", &scan_lvs);
-
-                       if (scan_lvs != cmd->scan_lvs) {
-                               log_debug("ignore hints with different scan_lvs");
+                       if ((sscanf(_hint_line + keylen, "%u", &scan_lvs) != 1) ||
+                           scan_lvs != cmd->scan_lvs) {
+                               log_debug("ignore hints with different or unreadable scan_lvs");
                                *needs_refresh = 1;
                                break;
                        }
@@ -728,7 +727,11 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
 
                keylen = strlen("devs_hash:");
                if (!strncmp(_hint_line, "devs_hash:", keylen)) {
-                       sscanf(_hint_line + keylen, "%u %u", &read_hash, &read_count);
+                       if (sscanf(_hint_line + keylen, "%u %u", &read_hash, &read_count) != 2) {
+                               log_debug("ignore hints with invalid devs_hash");
+                               *needs_refresh = 1;
+                               break;
+                       }
                        continue;
                }
 
This page took 0.036029 seconds and 5 git commands to generate.