From 6ee680515ff2c48ead6e5eb98e04cffa2cc50438 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Fri, 23 Aug 2019 09:44:41 +0200 Subject: [PATCH 1/3] Fix column filter keywords with quotes The quote marks in general search phrase keywords starting with "~", (like `~"abc"`) were not detected correctly. --- src/gmp_get.c | 17 ++++++++++++----- src/manage.h | 1 + src/manage_sql.c | 34 ++++++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/gmp_get.c b/src/gmp_get.c index 1b082da9d..b8c8ebdeb 100644 --- a/src/gmp_get.c +++ b/src/gmp_get.c @@ -518,6 +518,17 @@ buffer_get_filter_xml (GString *msg, const char* type, { keyword_t *keyword; keyword = *point; + const char *relation_symbol; + + if (keyword->equal) + relation_symbol = "="; + else if (keyword->approx) + relation_symbol = "~"; + else if (keyword_special (keyword)) + relation_symbol = ""; + else + relation_symbol = keyword_relation_symbol (keyword->relation); + buffer_xml_append_printf (msg, "" "%s" @@ -525,11 +536,7 @@ buffer_get_filter_xml (GString *msg, const char* type, "%s%s%s" "", keyword->column ? keyword->column : "", - keyword->equal - ? "=" - : (keyword_special (keyword) - ? "" - : keyword_relation_symbol (keyword->relation)), + relation_symbol, keyword->quoted ? "\"" : "", keyword->string ? keyword->string : "", keyword->quoted ? "\"" : ""); diff --git a/src/manage.h b/src/manage.h index 8730cc9df..ee863a910 100644 --- a/src/manage.h +++ b/src/manage.h @@ -3482,6 +3482,7 @@ typedef enum struct keyword { gchar *column; ///< The column prefix, or NULL. + int approx; ///< Whether the keyword is like "~example". int equal; ///< Whether the keyword is like "=example". int integer_value; ///< Integer value of the keyword. double double_value; ///< Floating point value of the keyword. diff --git a/src/manage_sql.c b/src/manage_sql.c index 2d07cb208..e61a67528 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -2033,6 +2033,8 @@ split_filter (const gchar* given_filter) keyword = g_malloc0 (sizeof (keyword_t)); if (*filter == '=') keyword->equal = 1; + else + keyword->approx = 1; current_part = filter + 1; between = 0; break; @@ -2125,9 +2127,11 @@ split_filter (const gchar* given_filter) in_quote = 1; current_part++; } - else if (keyword->equal && filter == current_part) + else if ((keyword->equal || keyword->approx) + && filter == current_part) { - /* A quoted exact term, like ="abc". */ + /* A quoted exact term, like ="abc" + * or a prefixed approximate term, like ~"abc". */ in_quote = 1; current_part++; } @@ -2692,14 +2696,24 @@ manage_clean_filter_remove (const gchar *filter, const gchar *column) break; } else - if (keyword->quoted) - g_string_append_printf (clean, " %s\"%s\"", - keyword->equal ? "=" : "", - keyword->string); - else - g_string_append_printf (clean, " %s%s", - keyword->equal ? "=" : "", - keyword->string); + { + const char *relation_symbol; + if (keyword->equal) + relation_symbol = "="; + else if (keyword->approx) + relation_symbol = "~"; + else + relation_symbol = ""; + + if (keyword->quoted) + g_string_append_printf (clean, " %s\"%s\"", + relation_symbol, + keyword->string); + else + g_string_append_printf (clean, " %s%s", + relation_symbol, + keyword->string); + } point++; } filter_free (split); From 198b80cbd418d29e1826ed3f6ee1a0a6ef9aa942 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Fri, 23 Aug 2019 09:44:41 +0200 Subject: [PATCH 2/3] Fix columnless filter keywords with quotes The quote marks in general search phrase keywords starting with "~", (like `~"abc"`) were not detected correctly. --- src/gmp_get.c | 17 ++++++++++++----- src/manage.h | 1 + src/manage_sql.c | 34 ++++++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/gmp_get.c b/src/gmp_get.c index 1b082da9d..b8c8ebdeb 100644 --- a/src/gmp_get.c +++ b/src/gmp_get.c @@ -518,6 +518,17 @@ buffer_get_filter_xml (GString *msg, const char* type, { keyword_t *keyword; keyword = *point; + const char *relation_symbol; + + if (keyword->equal) + relation_symbol = "="; + else if (keyword->approx) + relation_symbol = "~"; + else if (keyword_special (keyword)) + relation_symbol = ""; + else + relation_symbol = keyword_relation_symbol (keyword->relation); + buffer_xml_append_printf (msg, "" "%s" @@ -525,11 +536,7 @@ buffer_get_filter_xml (GString *msg, const char* type, "%s%s%s" "", keyword->column ? keyword->column : "", - keyword->equal - ? "=" - : (keyword_special (keyword) - ? "" - : keyword_relation_symbol (keyword->relation)), + relation_symbol, keyword->quoted ? "\"" : "", keyword->string ? keyword->string : "", keyword->quoted ? "\"" : ""); diff --git a/src/manage.h b/src/manage.h index 8730cc9df..ee863a910 100644 --- a/src/manage.h +++ b/src/manage.h @@ -3482,6 +3482,7 @@ typedef enum struct keyword { gchar *column; ///< The column prefix, or NULL. + int approx; ///< Whether the keyword is like "~example". int equal; ///< Whether the keyword is like "=example". int integer_value; ///< Integer value of the keyword. double double_value; ///< Floating point value of the keyword. diff --git a/src/manage_sql.c b/src/manage_sql.c index 2d07cb208..e61a67528 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -2033,6 +2033,8 @@ split_filter (const gchar* given_filter) keyword = g_malloc0 (sizeof (keyword_t)); if (*filter == '=') keyword->equal = 1; + else + keyword->approx = 1; current_part = filter + 1; between = 0; break; @@ -2125,9 +2127,11 @@ split_filter (const gchar* given_filter) in_quote = 1; current_part++; } - else if (keyword->equal && filter == current_part) + else if ((keyword->equal || keyword->approx) + && filter == current_part) { - /* A quoted exact term, like ="abc". */ + /* A quoted exact term, like ="abc" + * or a prefixed approximate term, like ~"abc". */ in_quote = 1; current_part++; } @@ -2692,14 +2696,24 @@ manage_clean_filter_remove (const gchar *filter, const gchar *column) break; } else - if (keyword->quoted) - g_string_append_printf (clean, " %s\"%s\"", - keyword->equal ? "=" : "", - keyword->string); - else - g_string_append_printf (clean, " %s%s", - keyword->equal ? "=" : "", - keyword->string); + { + const char *relation_symbol; + if (keyword->equal) + relation_symbol = "="; + else if (keyword->approx) + relation_symbol = "~"; + else + relation_symbol = ""; + + if (keyword->quoted) + g_string_append_printf (clean, " %s\"%s\"", + relation_symbol, + keyword->string); + else + g_string_append_printf (clean, " %s%s", + relation_symbol, + keyword->string); + } point++; } filter_free (split); From fa8a91c7d06edff688490f1790107748b79e446e Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Fri, 23 Aug 2019 10:07:28 +0200 Subject: [PATCH 3/3] Add CHANGELOG entry for filter fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f7845a2d..7086ad3cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix assignment of orphaned tickets to the current user [#685](https://github.com/greenbone/gvmd/pull/685) - Fix response from GET_VULNS when given vuln_id does not exists [#696](https://github.com/greenbone/gvmd/pull/696) - Make bulk tagging with a filter work if the resources are already tagged [#711](https://github.com/greenbone/gvmd/pull/711) +- Fix columnless search phrase filter keywords with quotes [#715](https://github.com/greenbone/gvmd/pull/715) ### Removed - The handling of NVT updates via OTP has been removed. [#575](https://github.com/greenbone/gvmd/pull/575)