Skip to content

Commit

Permalink
Add: Added reading of gzip files for CVEs and EPSS.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelmold committed Oct 21, 2024
1 parent 88cdf82 commit 02cb67f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/manage_sql_secinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <cjson/cJSON.h>
#include <gvm/base/gvm_sentry.h>
#include <bsd/unistd.h>
#include <gvm/util/compressutils.h>
#include <gvm/util/fileutils.h>
#include <gvm/util/jsonpull.h>
#include <gvm/util/xmlutils.h>
Expand Down Expand Up @@ -3046,7 +3047,7 @@ update_cve_json (const gchar *cve_path, GHashTable *hashed_cpes)

g_info ("Updating %s", full_path);

cve_file = fdopen (fd, "r");
cve_file = gvm_gzip_open_file_reader_fd (fd);
if (cve_file == NULL)
{
g_warning ("%s: Failed to open CVE file: %s",
Expand Down Expand Up @@ -3283,7 +3284,8 @@ update_scap_cves ()
gboolean read_json = FALSE;
while ((cve_path = g_dir_read_name (dir)))
{
if (fnmatch ("nvdcve-1.1-*.json", cve_path, 0) == 0)
if (fnmatch ("nvdcve-1.1-*.json.gz", cve_path, 0) == 0 ||
fnmatch ("nvdcve-1.1-*.json", cve_path, 0) == 0)
{
read_json = TRUE;
break;
Expand All @@ -3294,7 +3296,9 @@ update_scap_cves ()
count = 0;
while ((cve_path = g_dir_read_name (dir)))
{
if ((fnmatch ("nvdcve-1.1-*.json", cve_path, 0) == 0) && read_json)
if ((fnmatch ("nvdcve-1.1-*.json.gz", cve_path, 0) == 0 ||
fnmatch ("nvdcve-1.1-*.json", cve_path, 0) == 0)
&& read_json)
{
if (update_cve_json (cve_path, hashed_cpes))
{
Expand Down Expand Up @@ -3380,10 +3384,19 @@ update_epss_scores ()
inserts_t inserts;

current_json_path = g_build_filename (GVM_SCAP_DATA_DIR,
"epss-scores-current.json",
"epss-scores-current.json.gz",
NULL);
int fd = open(current_json_path, O_RDONLY);

if (fd < 0 && errno == ENOENT)
{
g_free (current_json_path);
current_json_path = g_build_filename (GVM_SCAP_DATA_DIR,
"epss-scores-current.json",
NULL);
fd = open(current_json_path, O_RDONLY);
}

if (fd < 0)
{
int ret;
Expand All @@ -3403,7 +3416,7 @@ update_epss_scores ()
return ret;
}

epss_scores_file = fdopen(fd, "r");
epss_scores_file = gvm_gzip_open_file_reader_fd (fd);
if (epss_scores_file == NULL)
{
g_warning ("%s: Failed to convert file descriptor to FILE*: %s",
Expand Down

0 comments on commit 02cb67f

Please sign in to comment.