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

[20.08] Lint params #590

Merged
merged 4 commits into from
Aug 26, 2020
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [20.08.1] (unreleased)

### Added
- Extend nasl lint to detect if function parameter is used twice. [#590](https://github.com/greenbone/openvas/pull/590)

### Fixed
- Fork vhosts before creating the socket.[#576](https://github.com/greenbone/openvas/pull/576)
- Check if another forked child has already added the same vhost. [#581](https://github.com/greenbone/openvas/pull/581)
Expand Down
31 changes: 31 additions & 0 deletions nasl/lint.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,37 @@ nasl_lint_def (lex_ctxt *lexic, tree_cell *st, int lint_mode,
finfo->caller_file = g_strdup (err_fname ? err_fname : nasl_name);
finfo->caller_func = g_strdup (current_fun_def);
*def_func_tree = g_slist_prepend (*def_func_tree, finfo);

/* Check if function parameters are used multiple times. Only check
* this if we are in lint mode 1 to not check it multiple times. */
if (lint_mode == 1)
{
GSList *func_params = NULL;
int linenum = st->line_nb;
tree_cell *args = st->link[0];
for (; args != NULL; args = args->link[1])
{
if (args->x.str_val)
{
/* Check if param was already used */
if (!g_slist_find_custom (func_params, args->x.str_val,
(GCompareFunc) list_cmp))
func_params =
g_slist_prepend (func_params, args->x.str_val);
else
{
g_message ("%s: Error at or near line %d. "
"Parameter \"%s\" passed to function \"%s\" "
"was provided multiple times.",
finfo->caller_file, linenum, args->x.str_val,
finfo->func_name);
g_slist_free (func_params);
return NULL;
}
}
}
g_slist_free (func_params);
}
}

switch (st->type)
Expand Down