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 "not regexp ..." filters #1482

Merged
merged 2 commits into from
Apr 13, 2021
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 @@ -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

Expand Down
38 changes: 24 additions & 14 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()",
Expand Down