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 columnless filter keywords with quotes #715

Merged
merged 4 commits into from
Aug 24, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 12 additions & 5 deletions src/gmp_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,18 +518,25 @@ 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,
"<keyword>"
"<column>%s</column>"
"<relation>%s</relation>"
"<value>%s%s%s</value>"
"</keyword>",
keyword->column ? keyword->column : "",
keyword->equal
? "="
: (keyword_special (keyword)
? ""
: keyword_relation_symbol (keyword->relation)),
relation_symbol,
keyword->quoted ? "\"" : "",
keyword->string ? keyword->string : "",
keyword->quoted ? "\"" : "");
Expand Down
1 change: 1 addition & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 24 additions & 10 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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);
Expand Down