Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit 9646a3b

Browse files
committed
Fix cve-check-update looping processing META files
META file should have key:value lines but if the NIST NVD website is down, instead of the META file, the page describing the site being down is downloaded instead, which results in cve-check-update getting stuck in a loop trying to process the invalid META file. This can also be reproduced easily by tweaking a valid META file to have a colon (:) as the first character in the file. fscanf fails match, and so doesn't update the file pointer, and the loop doesn't break if there is no match unless its EOF. Fix by using fgets to get lines, and fscanf to parse them to keep file pointer handling simple.
1 parent cbc2d0e commit 9646a3b

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/update.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,19 @@ static cve_string *nvdcve_make_fname(int year, const char *fext)
113113

114114
static char *nvdcve_meta_get_val(FILE *f, const char *field)
115115
{
116-
do {
117-
char field_name[256], field_value[256];
118-
int ret;
119-
120-
ret = fscanf(f, " %255[^: \f\n\r\t\v] :%255s", field_name, field_value);
116+
char field_name[MAX_META_FILE_KEY_VALUE_SIZE];
117+
char field_value[MAX_META_FILE_KEY_VALUE_SIZE];
118+
char line[MAX_META_FILE_LINE_SIZE];
119+
int ret;
120+
while (fgets(line, MAX_META_FILE_LINE_SIZE, f)) {
121+
ret = sscanf(line, " %255[^: ] : %255s", field_name, field_value);
121122
if (ret != 2) {
122-
if (ret != EOF) {
123-
continue;
124-
}
125-
if (ferror(f)) {
126-
if (errno == EINTR || errno == EAGAIN) {
127-
clearerr(f);
128-
continue;
129-
}
130-
}
131-
return NULL;
132-
}
133-
if (streq(field_name, field)) {
123+
fprintf(stderr, "Ignoring unparseable line in META file\n");
124+
} else if (streq(field_name, field)) {
134125
return strdup(field_value);
135126
}
136-
} while (1);
127+
}
128+
return NULL;
137129
}
138130

139131
static bool nvdcve_data_ok(const char *meta, const char *data)

src/update.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
#include "cve-string.h"
1313

14+
#define MAX_META_FILE_LINE_SIZE 512
15+
#define MAX_META_FILE_KEY_VALUE_SIZE 256
16+
1417
cve_string *get_db_path(const char *path);
1518

1619
int update_required(const char *db_file);

0 commit comments

Comments
 (0)