Skip to content

Fixing not escaped single quote in vuln detector SQL query#5570

Merged
chemamartinez merged 4 commits intodevelopfrom
5533-vuln-detector-query-error
Jul 31, 2020
Merged

Fixing not escaped single quote in vuln detector SQL query#5570
chemamartinez merged 4 commits intodevelopfrom
5533-vuln-detector-query-error

Conversation

@DProvinciani
Copy link
Contributor

Related issue
Issue 5533

Description

This PR adds a mechanism to escape a ' (single quote characters) from the string fields used in a vulnerability-detector SQL query. The escape sequence is '' (double single quotes) as specified by SQL language.
For performance reasons, we decided to only apply this logic to the vendor and package strings. It wouldn't be expected to have that kind of character in the CPE, version, or arch strings.

Tests

  • Compilation without warnings in every supported platform
    • Linux
    • Windows
    • MAC OS X
  • Source installation
  • Package installation
  • Source upgrade
  • Package upgrade

snprintf(buffer, OS_SIZE_6144, vu_queries[VU_SYSC_UPDATE_CPE],
// If the vendor or package string contains single quotation characters
// sqlite3_snprintf will escape them with double single quotes to avoid breaking the SQL query
sqlite3_snprintf(OS_SIZE_6144, buffer, vu_queries[VU_SYSC_UPDATE_CPE],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of this API resolves the issue of single quotes in the query.
https://www.sqlite.org/c3ref/mprintf.html
https://www.sqlite.org/printf.html#percentq

Copy link
Contributor

@chemamartinez chemamartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@DProvinciani DProvinciani marked this pull request as draft July 29, 2020 14:21
@DProvinciani DProvinciani marked this pull request as ready for review July 29, 2020 14:21
@DProvinciani DProvinciani marked this pull request as draft July 30, 2020 01:08
@DProvinciani DProvinciani marked this pull request as ready for review July 30, 2020 01:09
@DProvinciani DProvinciani marked this pull request as draft July 30, 2020 17:35
@DProvinciani DProvinciani marked this pull request as ready for review July 30, 2020 17:36
@chemamartinez chemamartinez merged commit e3b905a into develop Jul 31, 2020
@chemamartinez chemamartinez deleted the 5533-vuln-detector-query-error branch July 31, 2020 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vulnerability assesment gives error for windows agent

2 participants