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

Fix: Also create NVT indexes after rebuild #2247

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 29 additions & 17 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,33 @@
suffix);
}

/**
* @brief Create NVT related indexes.
*
* @param[in] suffix String to append to table names.
*/
void
create_indexes_nvt ()

Check warning on line 1890 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1890

Added line #L1890 was not covered by tests
{
sql ("SELECT create_index ('nvts_by_creation_time',"

Check warning on line 1892 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1892

Added line #L1892 was not covered by tests
" 'nvts',"
" 'creation_time');");
sql ("SELECT create_index ('nvts_by_family', 'nvts', 'family');");
sql ("SELECT create_index ('nvts_by_name', 'nvts', 'name');");
sql ("SELECT create_index ('nvts_by_modification_time',"

Check warning on line 1897 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1895-L1897

Added lines #L1895 - L1897 were not covered by tests
" 'nvts', 'modification_time');");
sql ("SELECT create_index ('nvts_by_cvss_base',"

Check warning on line 1899 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1899

Added line #L1899 was not covered by tests
" 'nvts', 'cvss_base');");
sql ("SELECT create_index ('nvts_by_solution_type',"

Check warning on line 1901 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1901

Added line #L1901 was not covered by tests
" 'nvts', 'solution_type');");

sql ("SELECT create_index ('vt_refs_by_vt_oid',"

Check warning on line 1904 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1904

Added line #L1904 was not covered by tests
" 'vt_refs', 'vt_oid');");

sql ("SELECT create_index ('vt_severities_by_vt_oid',"

Check warning on line 1907 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L1907

Added line #L1907 was not covered by tests
" 'vt_severities', 'vt_oid');");
}

/**
* @brief Create all tables.
*/
Expand Down Expand Up @@ -3021,17 +3048,8 @@
sql ("SELECT create_index ('nvt_selectors_by_name',"
" 'nvt_selectors',"
" 'name');");
sql ("SELECT create_index ('nvts_by_creation_time',"
" 'nvts',"
" 'creation_time');");
sql ("SELECT create_index ('nvts_by_family', 'nvts', 'family');");
sql ("SELECT create_index ('nvts_by_name', 'nvts', 'name');");
sql ("SELECT create_index ('nvts_by_modification_time',"
" 'nvts', 'modification_time');");
sql ("SELECT create_index ('nvts_by_cvss_base',"
" 'nvts', 'cvss_base');");
sql ("SELECT create_index ('nvts_by_solution_type',"
" 'nvts', 'solution_type');");

create_indexes_nvt ();

Check warning on line 3052 in src/manage_pg.c

View check run for this annotation

Codecov / codecov/patch

src/manage_pg.c#L3052

Added line #L3052 was not covered by tests

sql ("SELECT create_index ('permissions_by_name',"
" 'permissions', 'name');");
Expand Down Expand Up @@ -3063,12 +3081,6 @@
" 'tls_certificate_origins',"
" 'origin_id, origin_type')");

sql ("SELECT create_index ('vt_refs_by_vt_oid',"
" 'vt_refs', 'vt_oid');");

sql ("SELECT create_index ('vt_severities_by_vt_oid',"
" 'vt_severities', 'vt_oid');");

/* Previously this included the value column but that can be bigger than 8191,
* the maximum size that Postgres can handle. For example, this can happen
* for "ports". Mostly value is short, like a CPE for the "App" detail,
Expand Down
3 changes: 3 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ add_role_permission_resource (const gchar *, const gchar *, const gchar *,
void
create_view_vulns ();

void
create_indexes_nvt ();

int
config_family_entire_and_growing (config_t, const char*);

Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_nvts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,7 @@
sql ("ALTER TABLE nvts_rebuild RENAME TO nvts;");

create_view_vulns ();
create_indexes_nvt ();

Check warning on line 1990 in src/manage_sql_nvts.c

View check run for this annotation

Codecov / codecov/patch

src/manage_sql_nvts.c#L1990

Added line #L1990 was not covered by tests
}

set_nvts_check_time (count_new_vts, count_modified_vts);
Expand Down
Loading