Skip to content

Commit

Permalink
Don't add duplicated vhosts.
Browse files Browse the repository at this point in the history
Like the previous commit, but this check is done at host process level,
It does not removes the appended vhosts from internal/vhosts key (get instead pop)
So, avoids race condition in which other plugins checks for adding the same vhosts,
and they have an outdated vhosts list.
  • Loading branch information
jjnicola committed Aug 19, 2020
1 parent 50672c2 commit 6f94084
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,55 @@ unset_check_new_vhosts_flag (void)
static void
check_new_vhosts (void)
{
char *value;
struct kb_item *current_vhosts = NULL;

if (get_check_new_vhosts_flag () == 0)
return;

while ((value = kb_item_pop_str (host_kb, "internal/vhosts")))
/* Check for duplicate vhost value already added by other forked child of the
* same plugin. */
current_vhosts = kb_item_get_all (host_kb, "internal/vhosts");
if (!current_vhosts)
{
/* Get the source. */
char buffer[4096], *source;
unset_check_new_vhosts_flag ();
g_message ("no current vhosts");
return;
}
while (current_vhosts)
{
GSList *vhosts = NULL;
char buffer[4096], *source, *value;
gvm_vhost_t *vhost;

value = g_strdup (current_vhosts->v_str);

/* Check for duplicate vhost value in args. */
vhosts = host_vhosts;
while (vhosts)
{
gvm_vhost_t *tmp = vhosts->data;

if (!strcmp (tmp->value, value))
{
g_warning ("%s: Value '%s' exists already", __func__, value);
unset_check_new_vhosts_flag ();
kb_item_free (current_vhosts);
return;
}
vhosts = vhosts->next;
}

/* Get sources*/
g_snprintf (buffer, sizeof (buffer), "internal/source/%s", value);
source = kb_item_pop_str (host_kb, buffer);
source = kb_item_get_str (host_kb, buffer);
assert (source);
vhost = gvm_vhost_new (value, source);
host_vhosts = g_slist_append (host_vhosts, vhost);

current_vhosts = current_vhosts->next;
}

kb_item_free (current_vhosts);
unset_check_new_vhosts_flag ();
}

Expand Down

0 comments on commit 6f94084

Please sign in to comment.