From 3e927697f7b308564a52779addc12b3b12367f6e Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Mon, 12 Apr 2021 09:54:50 +0200 Subject: [PATCH 1/2] Fix "not regexp ..." filters Using the filters where a "regexp" clause was negated generated invalid SQL, which has been fixed. (cherry picked from commit b4bc23fcba7c1214e755ad627beddc98fe754bd3) --- src/manage_sql.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index a93d63d3b..9be43cca1 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -3732,20 +3732,30 @@ filter_clause (const char* type, const char* filter, if (keyword_applies_to_column (keyword, filter_column) && select_column && column_type_matches) - g_string_append_printf (clause, - "%s" - "(%s IS NULL" - " OR CAST (%s AS TEXT)" - " NOT %s '%s%s%s')", - (index ? " AND " : ""), - select_column, - select_column, - last_was_re - ? sql_regexp_op () - : sql_ilike_op (), - last_was_re ? "" : "%%", - quoted_keyword, - last_was_re ? "" : "%%"); + { + if (last_was_re) + g_string_append_printf (clause, + "%s" + "(%s IS NULL" + " OR NOT (CAST (%s AS TEXT)" + " %s '%s'))", + (index ? " AND " : ""), + select_column, + select_column, + sql_regexp_op (), + quoted_keyword); + else + g_string_append_printf (clause, + "%s" + "(%s IS NULL" + " OR CAST (%s AS TEXT)" + " NOT %s '%%%s%%')", + (index ? " AND " : ""), + select_column, + select_column, + sql_ilike_op (), + quoted_keyword); + } else g_string_append_printf (clause, "%s t ()", From df06a8ce6fd1bc8edc449c6dd1d9d6063242ca12 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Mon, 12 Apr 2021 10:04:31 +0200 Subject: [PATCH 2/2] Add CHANGELOG entry for "not regexp ..." fix (cherry picked from commit 60198038342c339908fa9d3d27982870410a5126) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82580cf3b..c7cb1e07c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Improve modify_override errors, fix no NVT case [#1435](https://github.com/greenbone/gvmd/pull/1435) - Fix size calculation in `--optimize vacuum` [#1447](https://github.com/greenbone/gvmd/pull/1447) - Fix report host end time check in CVE scans [#1462](https://github.com/greenbone/gvmd/pull/1462) +- Fix "not regexp ..." filters [#1482](https://github.com/greenbone/gvmd/pull/1482) ### Removed