|
OpenVAS Scanner 23.32.3
|
#include "lint.h"#include "exec.h"#include "nasl.h"#include "nasl_debug.h"#include "nasl_func.h"#include "nasl_global_ctxt.h"#include "nasl_init.h"#include "nasl_lex_ctxt.h"#include "nasl_tree.h"#include "nasl_var.h"#include <stdio.h>#include <string.h>#include <unistd.h>
Go to the source code of this file.
Data Structures | |
| struct | st_func_info |
| Define struct to store information about a called function. More... | |
Macros | |
| #define | G_LOG_DOMAIN "lib nasl" |
| GLib logging domain. | |
Typedefs | |
| typedef struct st_func_info | func_info |
| Define struct to store information about a called function. | |
Functions | |
| static void | init_errors_cnt () |
| static void | inc_errors_cnt () |
| static int | get_errors_cnt () |
| static void | free_list_func (func_info *data) |
| Free a func_info structure. | |
| static void | add_predef_varname (GSList **defined_var) |
| Add keywords to the varnames list. | |
| static gint | list_cmp1 (gconstpointer lelem, gconstpointer data) |
| This function is called by g_slist_find_custom. | |
| static gint | reverse_search (GSList **def_func_tree, GSList *finfo) |
| Check if an undefined called function is needed or not. This is the case in which the function is called from a nested and defined function but never called. | |
| static gint | list_cmp (gconstpointer lelem, gconstpointer data) |
| This function is called by g_slist_find_custom. | |
| static void | check_called_files (gpointer key, gpointer value, GSList **unusedfiles) |
| This function is called by g_hash_table_foreach to check if an include file was used or not. If the file is not used, it is added to a list. | |
| static void | print_uncall_files (gpointer filename, gpointer lexic) |
| It shows a msg for unused included files. | |
| static tree_cell * | nasl_lint_def (lex_ctxt *lexic, tree_cell *st, int lint_mode, GHashTable **include_files, GHashTable **func_fnames_tab, gchar *err_fname, GSList **called_funcs, GSList **def_func_tree) |
| Loads all defined functions. Also, It constructs a tree of called functions to help recognize a not defined function which is never called (nested functions). | |
| static char * | get_argument_by_name (tree_cell *st, char *name) |
| Checks if a given Arguments is within a given Argument List. | |
| static tree_cell * | validate_script_xref (lex_ctxt *lexic, tree_cell *st) |
| Validates parameters of a script_xref function call. | |
| static tree_cell * | validate_function (lex_ctxt *lexic, tree_cell *st) |
| Validate functions. | |
| static int | is_deffunc_used (const char *funcname, const char *filename, GSList *def_func_tree) |
| Returns 1 if the function is at least used once by another caller than filename otherwise 0. | |
| void | nasl_lint_feature_flags (int flag) |
| static tree_cell * | nasl_lint_call (lex_ctxt *lexic, tree_cell *st, GHashTable **include_files, GHashTable **func_fnames_tab, gchar *err_fname, GSList **called_funcs, GSList **def_func_tree) |
| Check if a called function was defined. | |
| static tree_cell * | nasl_lint_defvar (lex_ctxt *lexic, tree_cell *st, GHashTable **include_files, GHashTable **func_fnames_tab, gchar *err_fname, GSList **defined_var, GSList **called_funcs) |
| Consider all cases in which a variable is set, and add it to a list. If a variable is read, it checks if it was previously added to the list. | |
| static tree_cell * | make_call_func_list (lex_ctxt *lexic, tree_cell *st, GSList **called_funcs) |
| Make a list of all called functions. | |
| static tree_cell * | check_description_block_xref (lex_ctxt *lexic, tree_cell *st) |
| Sanity check of the script_xref parameters in the description block. | |
| static tree_cell * | check_description_block (lex_ctxt *lexic, tree_cell *st) |
| Sanity check of the description block. | |
| static tree_cell * | find_description_block (lex_ctxt *lexic, tree_cell *st) |
| Sanity check of the description block. | |
| tree_cell * | nasl_lint (lex_ctxt *lexic, tree_cell *st) |
| Search for errors in a nasl script. | |
Variables | |
| char * | nasl_name |
| int | errors_cnt |
| int | features = 0 |
| typedef struct st_func_info func_info |
Define struct to store information about a called function.
|
static |
Add keywords to the varnames list.
| [in,out] | defined_var | List with all defined variables |
Definition at line 81 of file lint.c.
References add_nasl_library().
Referenced by nasl_lint().


|
static |
This function is called by g_hash_table_foreach to check if an include file was used or not. If the file is not used, it is added to a list.
| [in] | key | Element key of GHashTable. |
| [in] | value | Element value for a key of GHashTable. |
| [in] | unusedfiles | List with unused .inc files. |
Definition at line 169 of file lint.c.
References nasl_get_include_order().
Referenced by nasl_lint().


Sanity check of the description block.
Definition at line 749 of file lint.c.
References check_description_block(), check_description_block_xref(), FAKE_CELL, TC::link, NODE_FUN_CALL, TC::str_val, TC::type, and TC::x.
Referenced by check_description_block(), and nasl_lint().


Sanity check of the script_xref parameters in the description block.
Definition at line 718 of file lint.c.
References check_description_block_xref(), CONST_STR, FAKE_CELL, TC::link, nasl_get_filename(), TC::str_val, TC::type, and TC::x.
Referenced by check_description_block(), and check_description_block_xref().


Sanity check of the description block.
Definition at line 773 of file lint.c.
References FAKE_CELL, find_description_block(), TC::link, NODE_IF_ELSE, NODE_VAR, TC::str_val, TC::type, and TC::x.
Referenced by find_description_block(), and nasl_lint().


|
static |
Free a func_info structure.
| [in] | defined_var | List with all defined variables |
Definition at line 66 of file lint.c.
References st_func_info::caller_file, st_func_info::caller_func, and st_func_info::func_name.
Referenced by nasl_lint().

|
static |
Checks if a given Arguments is within a given Argument List.
| st | Argument List, should be of Type NODE_ARG |
| name | Name of the Argument to search for |
Definition at line 317 of file lint.c.
References TC::link, name, NODE_ARG, TC::str_val, TC::type, and TC::x.
Referenced by validate_script_xref().

|
static |
Definition at line 54 of file lint.c.
References errors_cnt.
Referenced by nasl_lint().

|
static |
Definition at line 48 of file lint.c.
References errors_cnt.
Referenced by nasl_lint(), nasl_lint_defvar(), and print_uncall_files().

|
static |
Definition at line 43 of file lint.c.
References errors_cnt.
Referenced by nasl_lint().

|
static |
Returns 1 if the function is at least used once by another caller than filename otherwise 0.
Definition at line 405 of file lint.c.
References st_func_info::caller_file, and st_func_info::func_name.
Referenced by nasl_lint_call().

|
static |
This function is called by g_slist_find_custom.
| [in] | lelem | Element of GSList. |
| [in] | data | str to be found in the list. |
Definition at line 151 of file lint.c.
Referenced by nasl_lint_call(), nasl_lint_def(), and nasl_lint_defvar().

|
static |
This function is called by g_slist_find_custom.
| [in] | lelem | Element of GSList. |
| [in] | data | func_info structure to be found. |
Definition at line 101 of file lint.c.
Referenced by nasl_lint_call(), and reverse_search().

Make a list of all called functions.
Definition at line 687 of file lint.c.
References FAKE_CELL, get_func_ref_by_name(), TC::link, make_call_func_list(), NODE_FUN_CALL, TC::str_val, TC::type, and TC::x.
Referenced by make_call_func_list(), and nasl_lint().


Search for errors in a nasl script.
| [in] | lexic | nasl context. |
| [in] | st | structure tree of a nasl script. |
Definition at line 811 of file lint.c.
References add_predef_varname(), alloc_typed_cell(), check_called_files(), check_description_block(), FAKE_CELL, find_description_block(), free_lex_ctxt(), free_list_func(), get_errors_cnt(), TC::i_val, inc_errors_cnt(), init_empty_lex_ctxt(), init_errors_cnt(), make_call_func_list(), nasl_get_filename(), nasl_lint_call(), nasl_lint_def(), nasl_lint_defvar(), nasl_name, NODE_VAR, struct_lex_ctxt::oid, print_uncall_files(), struct_lex_ctxt::script_infos, TC::str_val, and TC::x.
Referenced by exec_nasl_script().


|
static |
Check if a called function was defined.
This checks if a defined function is called. If it is never called it does not go deeper.
Definition at line 438 of file lint.c.
References CONST_DATA, CONST_STR, decl_nasl_func(), FAKE_CELL, features, func_is_internal(), get_func_ref_by_name(), is_deffunc_used(), struct_lex_ctxt::line_nb, TC::line_nb, TC::link, list_cmp(), list_cmp1(), TC::name, nasl_get_filename(), nasl_get_include_order(), nasl_lint_call(), nasl_perror(), nasl_set_filename(), NLFF_STRICT_INCLUDES, NODE_FUN_CALL, NODE_FUN_DEF, reverse_search(), TC::str_val, TC::type, validate_function(), and TC::x.
Referenced by nasl_lint(), and nasl_lint_call().


|
static |
Loads all defined functions. Also, It constructs a tree of called functions to help recognize a not defined function which is never called (nested functions).
Definition at line 203 of file lint.c.
References st_func_info::caller_file, st_func_info::caller_func, decl_nasl_func(), FAKE_CELL, st_func_info::func_name, get_func_ref_by_name(), TC::line_nb, TC::link, list_cmp(), nasl_get_filename(), nasl_lint_def(), nasl_name, nasl_set_filename(), NODE_FUN_CALL, NODE_FUN_DEF, TC::str_val, TC::type, and TC::x.
Referenced by nasl_lint(), and nasl_lint_def().


|
static |
Consider all cases in which a variable is set, and add it to a list. If a variable is read, it checks if it was previously added to the list.
This checks if a defined function is called. If it is never called it does not go deeper.
It is a local variable and it is added in special list, which will be cleaned at the end of the function.
Leaving the function definition, the local variables list is cleaned.
Definition at line 557 of file lint.c.
References EXPR_INCR, EXPR_NOT, FAKE_CELL, inc_errors_cnt(), struct_lex_ctxt::line_nb, TC::line_nb, TC::link, list_cmp(), nasl_lint_defvar(), nasl_perror(), NODE_AFF, NODE_ARRAY_EL, NODE_DECL, NODE_FOREACH, NODE_FUN_CALL, NODE_FUN_DEF, NODE_GLOBAL, NODE_LOCAL, NODE_PLUS_EQ, NODE_VAR, TC::str_val, TC::type, and TC::x.
Referenced by nasl_lint(), and nasl_lint_defvar().


| void nasl_lint_feature_flags | ( | int | flag | ) |
|
static |
It shows a msg for unused included files.
| [in] | filename | Filename of the not used inc file. |
| [in] | lexic | nasl context. |
Definition at line 186 of file lint.c.
References inc_errors_cnt(), and nasl_perror().
Referenced by nasl_lint().


|
static |
Check if an undefined called function is needed or not. This is the case in which the function is called from a nested and defined function but never called.
Definition at line 118 of file lint.c.
References st_func_info::caller_file, st_func_info::caller_func, st_func_info::func_name, list_cmp1(), nasl_name, and reverse_search().
Referenced by nasl_lint_call(), and reverse_search().


Validate functions.
| lexic | |
| st |
Definition at line 386 of file lint.c.
References FAKE_CELL, struct_lex_ctxt::line_nb, TC::line_nb, TC::link, TC::str_val, validate_script_xref(), and TC::x.
Referenced by nasl_lint_call().


Validates parameters of a script_xref function call.
| lexic | |
| st | Function Parameters should be of type NODE_ARG |
Definition at line 343 of file lint.c.
References FAKE_CELL, get_argument_by_name(), name, and nasl_perror().
Referenced by validate_function().


| int errors_cnt |
Definition at line 41 of file lint.c.
Referenced by get_errors_cnt(), inc_errors_cnt(), and init_errors_cnt().
| int features = 0 |
Definition at line 426 of file lint.c.
Referenced by nasl_lint_call(), and nasl_lint_feature_flags().
| char* nasl_name |
Definition at line 39 of file lint.c.
Referenced by nasl_lint(), nasl_lint_def(), and reverse_search().