1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-10 16:58:47 +03:00

hints: validate sscanf results

This commit is contained in:
Zdenek Kabelac 2019-11-14 17:59:17 +01:00
parent d4d82dbb70
commit 219fe72359

View File

@ -716,10 +716,9 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
keylen = strlen("scan_lvs:"); keylen = strlen("scan_lvs:");
if (!strncmp(_hint_line, "scan_lvs:", keylen)) { if (!strncmp(_hint_line, "scan_lvs:", keylen)) {
int scan_lvs = 0; int scan_lvs = 0;
sscanf(_hint_line + keylen, "%u", &scan_lvs); if ((sscanf(_hint_line + keylen, "%u", &scan_lvs) != 1) ||
scan_lvs != cmd->scan_lvs) {
if (scan_lvs != cmd->scan_lvs) { log_debug("ignore hints with different or unreadable scan_lvs");
log_debug("ignore hints with different scan_lvs");
*needs_refresh = 1; *needs_refresh = 1;
break; break;
} }
@ -728,7 +727,11 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int *
keylen = strlen("devs_hash:"); keylen = strlen("devs_hash:");
if (!strncmp(_hint_line, "devs_hash:", keylen)) { 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; continue;
} }