Skip to content

Commit

Permalink
Improved the handling of the escaping of colons.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelmold committed Oct 28, 2024
1 parent 0fb31ce commit dc00cfc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
17 changes: 13 additions & 4 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,6 +794,7 @@ 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
Expand All @@ -801,23 +803,30 @@ get_fs_component (const char *fs_cpe, int index)
{
if (*c == ':' && c == fs_cpe)
i++;
else if (c > fs_cpe && *c == ':' && *(c - 1) != '\\')
else 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++)
{
if (*c == ':' && c == component_start)
break;
else if (c > component_start && *c == ':' && *(c - 1) != '\\')
if (*c == ':' && !escaped)
break;
if (*c == '\\' && !escaped)
escaped = TRUE;
else
escaped = FALSE;
}
}

Expand Down
9 changes: 9 additions & 0 deletions util/cpeutils_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ Ensure (cpeutils, fs_cpe_to_uri_cpe)
"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: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 dc00cfc

Please sign in to comment.