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: Fixed the problem with escaped colons in fs CPEs. #847

Merged
merged 5 commits into from
Nov 2, 2024
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
22 changes: 17 additions & 5 deletions util/cpeutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ get_fs_component (const char *fs_cpe, int index)
char *component = NULL;
char *c;
char *component_start, *component_end;
gboolean escaped;

if (!fs_cpe)
return NULL;
Expand All @@ -793,27 +794,38 @@ get_fs_component (const char *fs_cpe, int index)
c = (char *) fs_cpe;

/* find start of component */
escaped = FALSE;
if (index == 0)
component_start = c;
else
{
for (int i = 0; *c != '\0' && i < index; c++)
{
if (*c == ':' && c == fs_cpe)
i++;
else if (c > fs_cpe && *c == ':' && *(c - 1) != '\\')
if (*c == ':' && !escaped)
i++;
else if (*c == '\\' && !escaped)
escaped = TRUE;
else
escaped = FALSE;
}
component_start = c;
}

/* find end of component */
escaped = FALSE;
if (*component_start == '\0')
component_end = component_start;
else
{
for (c = component_start; *c != '\0' && *c != ':'; c++)
;
for (c = component_start; *c != '\0'; c++)
{
if (*c == ':' && !escaped)
break;
if (*c == '\\' && !escaped)
escaped = TRUE;
else
escaped = FALSE;
}
}

component_end = c;
Expand Down
37 changes: 37 additions & 0 deletions util/cpeutils_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,43 @@ Ensure (cpeutils, fs_cpe_to_uri_cpe)
"cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win2003~x64~"));
g_free (uri_cpe);

fs_cpe =
"cpe:2.3:a:hp:insight_diagnostics:7\\:4.0.1570:-:*:*:online:win2003:x64:*";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
assert_that (
uri_cpe,
is_equal_to_string (
"cpe:/a:hp:insight_diagnostics:7%3A4.0.1570:-:~~online~win2003~x64~"));
g_free (uri_cpe);

fs_cpe =
"cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:win\\:2003:x64:*";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
assert_that (
uri_cpe,
is_equal_to_string (
"cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win%3A2003~x64~"));
g_free (uri_cpe);

fs_cpe = "cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:win\\:\\:"
"2003:x64:*";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
assert_that (
uri_cpe,
is_equal_to_string (
"cpe:/"
"a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win%3A%3A2003~x64~"));
g_free (uri_cpe);

fs_cpe = "cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:"
"win2003\\\\:x64:*";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
assert_that (
uri_cpe,
is_equal_to_string (
"cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win2003%5C~x64~"));
g_free (uri_cpe);

fs_cpe = "This is a ~:SIGNAL:~ test.";
uri_cpe = fs_cpe_to_uri_cpe (fs_cpe);
g_free (uri_cpe);
Expand Down