Skip to content

Commit

Permalink
Match nvt preference names with g_strsplit().
Browse files Browse the repository at this point in the history
Instead of using sscanf().
  • Loading branch information
kroosec committed Feb 17, 2019
1 parent c97cf86 commit 01fb573
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
19 changes: 8 additions & 11 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1676,18 +1676,15 @@ send_config_preferences (config_t config, const char* section_name,

if (pref_files)
{
int type_start = -1, type_end = -1, count;

char **splits;
int is_file = 0;
/* OID:PrefType:PrefName value */
count = sscanf (pref_name, "%*[^:]:%n%*[^:]%n:", &type_start,
&type_end);
if (count == 0
&& type_start > 0
&& type_end > 0
&& (strncmp (pref_name + type_start,
"file",
type_end - type_start)
== 0))
splits = g_strsplit (pref_name, ":", 3);
if (splits && g_strv_length (splits) == 3
&& strcmp (splits[1], "file") == 0)
is_file = 1;
g_strfreev (splits);
if (is_file)
{
GSList *head;
char *uuid;
Expand Down
18 changes: 9 additions & 9 deletions src/otp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,19 +1346,19 @@ process_otp_scanner_input ()
}

{
int value_start = -1, value_end = -1, count;
char name[128];
char **splits;
/* OID:PrefType:PrefName value */
count = sscanf (field, "%128[^:]:%*[^:]:%n%*[ -~]%n",
name, &value_start, &value_end);
if (count == 1 && value_start > 0 && value_end > 0
&& ((strcmp (name, OID_SSH_AUTH) == 0)
|| (strcmp (name, OID_SNMP_AUTH) == 0)
|| (strcmp (name, OID_ESXI_AUTH) == 0)
|| (strcmp (name, OID_SMB_AUTH) == 0)))

splits = g_strsplit (field, ":", 3);
if (splits && g_strv_length (splits) == 3
&& ((strcmp (splits[0], OID_SSH_AUTH) == 0)
|| (strcmp (splits[0], OID_SNMP_AUTH) == 0)
|| (strcmp (splits[0], OID_ESXI_AUTH) == 0)
|| (strcmp (splits[0], OID_SMB_AUTH) == 0)))
current_scanner_preference = NULL;
else
current_scanner_preference = g_strdup (field);
g_strfreev (splits);
set_scanner_state (SCANNER_PREFERENCE_VALUE);
switch (parse_scanner_preference_value (&messages))
{
Expand Down

0 comments on commit 01fb573

Please sign in to comment.