Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Use new EPSS file name and format #2290

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/manage_sql_secinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2860,21 +2860,22 @@
update_epss_scores ()
{
GError *error = NULL;
gchar *latest_json_path;
gchar *current_json_path;
gchar *file_contents = NULL;
cJSON *parsed, *list_item;
cJSON *parsed, *epss_scores_list, *list_item;
inserts_t inserts;

latest_json_path = g_build_filename (GVM_SCAP_DATA_DIR, "epss-latest.json",
NULL);
current_json_path = g_build_filename (GVM_SCAP_DATA_DIR,

Check warning on line 2868 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2868

Added line #L2868 was not covered by tests
"epss-scores-current.json",
NULL);

if (! g_file_get_contents (latest_json_path, &file_contents, NULL, &error))
if (! g_file_get_contents (current_json_path, &file_contents, NULL, &error))
{
int ret;
if (error->code == G_FILE_ERROR_NOENT)
{
g_info ("%s: EPSS scores file '%s' not found",
__func__, latest_json_path);
__func__, current_json_path);
ret = 0;
}
else
Expand All @@ -2884,12 +2885,12 @@
ret = -1;
}
g_error_free (error);
g_free (latest_json_path);
g_free (current_json_path);

Check warning on line 2888 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2888

Added line #L2888 was not covered by tests
return ret;
}

g_info ("Updating EPSS scores from %s", latest_json_path);
g_free (latest_json_path);
g_info ("Updating EPSS scores from %s", current_json_path);
g_free (current_json_path);

Check warning on line 2893 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2892-L2893

Added lines #L2892 - L2893 were not covered by tests

parsed = cJSON_Parse (file_contents);
g_free (file_contents);
Expand All @@ -2900,9 +2901,18 @@
return -1;
}

if (! cJSON_IsArray (parsed))
if (! cJSON_IsObject (parsed))
{
g_warning ("%s: EPSS scores file is not a JSON array", __func__);
g_warning ("%s: EPSS scores file is not a JSON object", __func__);
cJSON_Delete (parsed);
return -1;

Check warning on line 2908 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2906-L2908

Added lines #L2906 - L2908 were not covered by tests
}

epss_scores_list = cJSON_GetObjectItem (parsed, "epss_scores");

Check warning on line 2911 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2911

Added line #L2911 was not covered by tests
if (epss_scores_list == NULL)
{
g_warning ("%s: Missing epss_scores field",

Check warning on line 2914 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2914

Added line #L2914 was not covered by tests
__func__);
cJSON_Delete (parsed);
return -1;
}
Expand All @@ -2916,7 +2926,7 @@
" VALUES ",
" ON CONFLICT (cve) DO NOTHING");

cJSON_ArrayForEach (list_item, parsed)
cJSON_ArrayForEach (list_item, epss_scores_list)

Check warning on line 2929 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2929

Added line #L2929 was not covered by tests
{
cJSON *cve_json, *epss_json, *percentile_json;

Expand Down
Loading