Skip to content

Commit

Permalink
Fix: Clean up in update_scap_affected_products, fix CLI option
Browse files Browse the repository at this point in the history
The update_scap_affected_products function now frees the buffer of
CVE ids used in its SQL and the CVEs iterator.
Also, the affected_products_query_size is now set correctly.
  • Loading branch information
timopollmeier committed Jan 30, 2025
1 parent a85a51b commit 6408bc1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/manage_sql_secinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4088,14 +4088,14 @@ update_scap_affected_products ()
{
iterator_t cves_iter;
GString *cve_ids_buffer;
g_info ("Updating affected products");
int count = 0;

init_iterator(&cves_iter,
"SELECT DISTINCT cve_id FROM scap2.cpe_match_nodes");
g_info ("Updating affected products");

int count = 0;
init_iterator (&cves_iter,
"SELECT DISTINCT cve_id FROM scap2.cpe_match_nodes");

cve_ids_buffer = g_string_new("");
cve_ids_buffer = g_string_new ("");
while (next (&cves_iter))
{
resource_t cve_id;
Expand All @@ -4112,13 +4112,14 @@ update_scap_affected_products ()
g_debug ("%s: Products of %d CVEs processed", __func__, count);
}
}
cleanup_iterator (&cves_iter);

if (cve_ids_buffer->len)
{
exec_affected_products_sql (cve_ids_buffer->str);
g_string_truncate (cve_ids_buffer, 0);
g_debug ("%s: Products of %d CVEs processed", __func__, count);
}
g_free (cve_ids_buffer);

}

Expand Down Expand Up @@ -5842,7 +5843,7 @@ set_affected_products_query_size (int new_size)
if (new_size <= 0)
affected_products_query_size = AFFECTED_PRODUCTS_QUERY_SIZE_DEFAULT;
else
secinfo_commit_size = new_size;
affected_products_query_size = new_size;
}

/**
Expand Down

2 comments on commit 6408bc1

@Virsacer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I get an error with 24.3.3 when updating scap-data, which seems to be related to this change:

md manage:   INFO:2025-01-30 20h38.02 utc:377: Updating /gvm/var/lib/gvm/scap-data/nvdcve-2.0-2019.xml
md manage:   INFO:2025-01-30 20h39.26 utc:377: Updating affected products
free(): invalid pointer
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: gvmd(+0x6ffec) [0x564ad4ae8fec]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: /lib/x86_64-linux-gnu/libc.so.6(+0x3c050) [0x7fdfd6cc2050]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: /lib/x86_64-linux-gnu/libc.so.6(+0x8aebc) [0x7fdfd6d10ebc]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x12) [0x7fdfd6cc1fb2]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: /lib/x86_64-linux-gnu/libc.so.6(abort+0xd3) [0x7fdfd6cac472]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: /lib/x86_64-linux-gnu/libc.so.6(+0x7f430) [0x7fdfd6d05430]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: /lib/x86_64-linux-gnu/libc.so.6(+0x9483a) [0x7fdfd6d1a83a]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: /lib/x86_64-linux-gnu/libc.so.6(+0x965c4) [0x7fdfd6d1c5c4]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: /lib/x86_64-linux-gnu/libc.so.6(__libc_free+0x6f) [0x7fdfd6d1ef1f]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: gvmd(+0xe7080) [0x564ad4b60080]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: gvmd(manage_sync_scap+0x65) [0x564ad4b637b5]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: gvmd(manage_sync+0x99) [0x564ad4af9809]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: gvmd(+0x70a92) [0x564ad4ae9a92]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: gvmd(gvmd+0x1c3c) [0x564ad4aec25c]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: /lib/x86_64-linux-gnu/libc.so.6(+0x2724a) [0x7fdfd6cad24a]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85) [0x7fdfd6cad305]
md   main:MESSAGE:2025-01-30 20h39.26 utc:377: BACKTRACE: gvmd(_start+0x21) [0x564ad4ae87f1]
md manage:MESSAGE:2025-01-30 20h39.26 utc:377: Received Aborted signal

@bjoernricks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the hint! #2364 should address the issue.

Please sign in to comment.