Skip to content

Commit

Permalink
Some amendments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelmold committed Sep 18, 2024
1 parent 9e82c6a commit 00228d6
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions src/manage_sql_secinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2712,19 +2712,15 @@ json_object_item_double (cJSON *object, char *key, double fallback)
static int
save_node (long int parent_id, long int cve_id, char * operator)

Check warning on line 2713 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2713

Added line #L2713 was not covered by tests
{
long int id;

id = sql_int64_0
("INSERT INTO scap2.cpe_match_nodes"
" (parent_id, cve_id, operator)"
" VALUES"
" (%i, %i, '%s')"
" RETURNING scap2.cpe_match_nodes.id;",
parent_id,
cve_id,
operator);

return id;
return sql_int64_0

Check warning on line 2715 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2715

Added line #L2715 was not covered by tests
("INSERT INTO scap2.cpe_match_nodes"
" (parent_id, cve_id, operator)"
" VALUES"
" (%i, %i, '%s')"
" RETURNING scap2.cpe_match_nodes.id;",
parent_id,
cve_id,
operator);
}

/**
Expand Down Expand Up @@ -2781,8 +2777,8 @@ add_cpe_match_rules (long int id, cJSON *match_rules)
sql

Check warning on line 2777 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2777

Added line #L2777 was not covered by tests
("INSERT INTO scap2.cpe_match_range"
" (node_id, vulnerable, cpe,"
" version_start_incl, version_start_excl,"
" version_end_incl, version_end_excl)"
" version_start_incl, version_start_excl,"
" version_end_incl, version_end_excl)"
" VALUES"
" (%ld, %d, '%s', '%s', '%s', '%s', '%s')",
id,
Expand Down Expand Up @@ -2821,12 +2817,17 @@ load_nodes (long int parent_id, long int cveid, cJSON *nodes)
cpe_match_rules = NULL;
child_nodes = NULL;

Check warning on line 2818 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2814-L2818

Added lines #L2814 - L2818 were not covered by tests

if (nodes == NULL)
return;

Check warning on line 2821 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2821

Added line #L2821 was not covered by tests

cJSON_ArrayForEach(node, nodes)

Check warning on line 2823 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2823

Added line #L2823 was not covered by tests
{
operator = cJSON_GetObjectItemCaseSensitive(node, "operator");

Check warning on line 2825 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2825

Added line #L2825 was not covered by tests
id = save_node (parent_id, cveid, operator->valuestring);
if (operator)
id = save_node (parent_id, cveid, operator->valuestring);
cpe_match_rules = cJSON_GetObjectItemCaseSensitive(node, "cpe_match");

Check warning on line 2828 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2827-L2828

Added lines #L2827 - L2828 were not covered by tests
add_cpe_match_rules (id, cpe_match_rules);
if (cpe_match_rules)
add_cpe_match_rules (id, cpe_match_rules);
child_nodes = cJSON_GetObjectItemCaseSensitive(node, "children");
load_nodes (id, cveid, child_nodes);

Check warning on line 2832 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L2830-L2832

Added lines #L2830 - L2832 were not covered by tests
}
Expand All @@ -2847,7 +2848,7 @@ handle_json_cve_item (cJSON *item)
cJSON *cve_data_meta_json;

char *cve_id;
long int cve_db_id;
resource_t cve_db_id;

cve_json = cJSON_GetObjectItemCaseSensitive(item, "cve");
cve_data_meta_json = cJSON_GetObjectItemCaseSensitive(cve_json, "CVE_data_meta");
Expand Down Expand Up @@ -3028,15 +3029,15 @@ update_cve_json (const gchar *cve_path, GHashTable *hashed_cpes)
gvm_json_pull_event_t event;
gvm_json_pull_parser_t parser;
gchar *full_path;
GStatBuf state;
int transaction_size = 0;

Check warning on line 3032 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3032

Added line #L3032 was not covered by tests
// int ret;

full_path = g_build_filename (GVM_SCAP_DATA_DIR, cve_path, NULL);

Check warning on line 3034 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3034

Added line #L3034 was not covered by tests

if (g_stat (full_path, &state))
int fd = open (full_path, O_RDONLY);

Check warning on line 3036 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3036

Added line #L3036 was not covered by tests

if (fd < 0)
{
g_warning ("%s: Failed to stat SCAP file: %s",
g_warning ("%s: Failed to open CVE file: %s",

Check warning on line 3040 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3040

Added line #L3040 was not covered by tests
__func__,
strerror (errno));
g_free (full_path);
Expand All @@ -3045,7 +3046,7 @@ update_cve_json (const gchar *cve_path, GHashTable *hashed_cpes)

g_info ("Updating %s", full_path);

Check warning on line 3047 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3047

Added line #L3047 was not covered by tests

cve_file = fopen (full_path, "r");
cve_file = fdopen (fd, "r");

Check warning on line 3049 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3049

Added line #L3049 was not covered by tests
if (cve_file == NULL)
{
g_warning ("%s: Failed to open CVE file: %s",

Check warning on line 3052 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3052

Added line #L3052 was not covered by tests
Expand All @@ -3067,9 +3068,9 @@ update_cve_json (const gchar *cve_path, GHashTable *hashed_cpes)
while (!cve_items_found)
{
gvm_json_pull_parser_next (&parser, &event);
gvm_json_path_elem_t *path_tail = g_queue_peek_tail (event.path);
if (event.type == GVM_JSON_PULL_EVENT_ARRAY_START &&
strcmp (path_tail->key, "CVE_Items") == 0)
gvm_json_path_elem_t *path_tail = g_queue_peek_tail (event.path);

Check warning on line 3071 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3070-L3071

Added lines #L3070 - L3071 were not covered by tests
if (event.type == GVM_JSON_PULL_EVENT_ARRAY_START && path_tail &&
path_tail->key && strcmp (path_tail->key, "CVE_Items") == 0)

Check warning on line 3073 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3073

Added line #L3073 was not covered by tests
{
cve_items_found = TRUE;

Check warning on line 3075 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3075

Added line #L3075 was not covered by tests
}
Expand All @@ -3091,6 +3092,7 @@ update_cve_json (const gchar *cve_path, GHashTable *hashed_cpes)
}
}
gvm_json_pull_parser_next (&parser, &event);
sql_begin_immediate ();

Check warning on line 3095 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3094-L3095

Added lines #L3094 - L3095 were not covered by tests
while (event.type == GVM_JSON_PULL_EVENT_OBJECT_START)
{
entry = gvm_json_pull_expand_container (&parser, &error_message);

Check warning on line 3098 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3098

Added line #L3098 was not covered by tests
Expand All @@ -3099,19 +3101,25 @@ update_cve_json (const gchar *cve_path, GHashTable *hashed_cpes)
g_warning ("%s: Error expanding CVE item: %s", __func__, error_message);
gvm_json_pull_event_cleanup (&event);
gvm_json_pull_parser_cleanup (&parser);
cJSON_Delete (entry);
fclose (cve_file);
sql_commit ();
return -1;

Check warning on line 3107 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3101-L3107

Added lines #L3101 - L3107 were not covered by tests
}
if (handle_json_cve_item (entry))
{
gvm_json_pull_event_cleanup (&event);
gvm_json_pull_parser_cleanup (&parser);
cJSON_Delete (entry);
fclose (cve_file);
sql_commit ();
return -1;

Check warning on line 3116 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3111-L3116

Added lines #L3111 - L3116 were not covered by tests
}
increment_transaction_size (&transaction_size);
cJSON_Delete (entry);
gvm_json_pull_parser_next (&parser, &event);

Check warning on line 3120 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3118-L3120

Added lines #L3118 - L3120 were not covered by tests
}
}
sql_commit ();

Check warning on line 3122 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3122

Added line #L3122 was not covered by tests
}
else if (event.type == GVM_JSON_PULL_EVENT_ERROR)

Check warning on line 3124 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3124

Added line #L3124 was not covered by tests
{
Expand Down Expand Up @@ -3286,7 +3294,7 @@ update_scap_cves ()
}
count++;

Check warning on line 3295 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3295

Added line #L3295 was not covered by tests
}
if (fnmatch ("nvdcve-2.0-*.xml", cve_path, 0) == 0)
else if (fnmatch ("nvdcve-2.0-*.xml", cve_path, 0) == 0)

Check warning on line 3297 in src/manage_sql_secinfo.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_secinfo.c#L3297

Added line #L3297 was not covered by tests
{
if (update_cve_xml (cve_path, hashed_cpes))
{
Expand Down

0 comments on commit 00228d6

Please sign in to comment.