From b4bc23fcba7c1214e755ad627beddc98fe754bd3 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. --- 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 0d5f2ea2a..7dd1e9e99 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -3794,20 +3794,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 60198038342c339908fa9d3d27982870410a5126 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 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78753ed7d..5349c8b32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,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