Skip to content

Commit

Permalink
Merge pull request #847 from greenbone/GEA-635_Use_compression_in_fee…
Browse files Browse the repository at this point in the history
…d_updates_CPEs

Fix: Fixed the problem with escaped colons in fs CPEs.
  • Loading branch information
mattmundell authored Nov 2, 2024
2 parents a905955 + 5a4474b commit 08ef292
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
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

0 comments on commit 08ef292

Please sign in to comment.