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

Add: Cache prefs in nvti_cache for handle_get_nvts #2096

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 10 additions & 2 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13636,8 +13636,16 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error)

if (get_nvts_data->preference_count)
{
const char *nvt_oid = nvt_iterator_oid (&nvts);
pref_count = nvt_preference_count (nvt_oid);
const char *nvt_oid;
nvti_t *nvti;

nvt_oid = nvt_iterator_oid (&nvts);

nvti = lookup_nvti (nvt_oid);
if (nvti)
pref_count = nvti_pref_len (nvti);
else
pref_count = nvt_preference_count (nvt_oid);
}
if (send_nvt (&nvts, 1, get_nvts_data->preferences,
pref_count, timeout, config,
Expand Down
20 changes: 19 additions & 1 deletion src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -15611,7 +15611,7 @@ lookup_nvti (const gchar *nvt)
static void
update_nvti_cache ()
{
iterator_t nvts;
iterator_t nvts, prefs;

nvtis_free (nvti_cache);

Expand All @@ -15631,6 +15631,11 @@ update_nvti_cache ()
" FROM nvts"
" LEFT OUTER JOIN vt_refs ON nvts.oid = vt_refs.vt_oid;");

init_iterator (&prefs,
"SELECT pref_id, pref_nvt, pref_name, value"
" FROM nvt_preferences"
" WHERE NOT (pref_type = 'entry' AND pref_name = 'Timeout')");
mattmundell marked this conversation as resolved.
Show resolved Hide resolved

while (next (&nvts))
{
nvti_t *nvti;
Expand All @@ -15642,6 +15647,18 @@ update_nvti_cache ()
nvti_set_oid (nvti, iterator_string (&nvts, 0));

nvtis_add (nvti_cache, nvti);

while (next (&prefs))
if (iterator_string (&prefs, 1)
&& (strcmp (iterator_string (&prefs, 1),
iterator_string (&nvts, 0))
== 0))
nvti_add_pref (nvti,
nvtpref_new (iterator_int (&prefs, 0),
iterator_string (&prefs, 2),
iterator_string (&prefs, 3),
NULL));
iterator_rewind (&prefs);
}

if (iterator_null (&nvts, 2))
Expand All @@ -15654,6 +15671,7 @@ update_nvti_cache ()
}

cleanup_iterator (&nvts);
cleanup_iterator (&prefs);

malloc_trim (0);
}
Expand Down