OpenVAS Scanner
7.0.0~git
|
#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 <string.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. More... | |
Typedefs | |
typedef struct st_func_info | func_info |
Define struct to store information about a called function. More... | |
Functions | |
void | free_list_func (func_info *data) |
Free a func_info structure. More... | |
void | add_predef_varname (GSList **defined_var) |
Add keywords to the varnames list. More... | |
gint | list_cmp1 (gconstpointer lelem, gconstpointer data) |
This function is called by g_slist_find_custom. More... | |
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 neested and defined function but never called. More... | |
gint | list_cmp (gconstpointer lelem, gconstpointer data) |
This function is called by g_slist_find_custom. More... | |
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. More... | |
void | print_uncall_files (gpointer filename, gpointer lexic) |
It shows a msg for unused included files. More... | |
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). More... | |
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. More... | |
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. More... | |
tree_cell * | make_call_func_list (lex_ctxt *lexic, tree_cell *st, GSList **called_funcs) |
Make a list of all called functions. More... | |
tree_cell * | nasl_lint (lex_ctxt *lexic, tree_cell *st) |
Search for errors in a nasl script. More... | |
Variables | |
char * | nasl_name |
typedef struct st_func_info func_info |
Define struct to store information about a called function.
void add_predef_varname | ( | GSList ** | defined_var | ) |
Add keywords to the varnames list.
[in,out] | defined_var | List with all defined variables |
Definition at line 70 of file lint.c.
References add_nasl_library().
Referenced by nasl_lint().
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.
[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 159 of file lint.c.
Referenced by nasl_lint().
void free_list_func | ( | func_info * | data | ) |
Free a func_info structure.
[in] | defined_var | List with all defined variables |
Definition at line 55 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().
gint list_cmp | ( | gconstpointer | lelem, |
gconstpointer | data | ||
) |
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 140 of file lint.c.
Referenced by nasl_lint_call(), nasl_lint_def(), and nasl_lint_defvar().
gint list_cmp1 | ( | gconstpointer | lelem, |
gconstpointer | data | ||
) |
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 90 of file lint.c.
Referenced by nasl_lint_call(), and reverse_search().
Make a list of all called functions.
Definition at line 461 of file lint.c.
References FAKE_CELL, get_func_ref_by_name(), TC::link, NODE_FUN_CALL, TC::str_val, TC::type, and TC::x.
Referenced by nasl_lint().
Search for errors in a nasl script.
[in] | lexic | nasl context. |
[in] | st | structure tree of a nasl script. |
Definition at line 497 of file lint.c.
References add_predef_varname(), check_called_files(), FAKE_CELL, free_lex_ctxt(), free_list_func(), init_empty_lex_ctxt(), make_call_func_list(), nasl_get_filename(), nasl_lint_call(), nasl_lint_def(), nasl_lint_defvar(), nasl_name, struct_lex_ctxt::oid, print_uncall_files(), struct_lex_ctxt::script_infos, TC::str_val, and TC::x.
Referenced by exec_nasl_script().
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.
This checks if a defined function is called. If it is never called it does not go deeper.
Definition at line 270 of file lint.c.
References CONST_DATA, CONST_STR, decl_nasl_func(), FAKE_CELL, get_func_ref_by_name(), struct_lex_ctxt::line_nb, TC::line_nb, TC::link, list_cmp(), list_cmp1(), nasl_get_filename(), nasl_perror(), nasl_set_filename(), NODE_FUN_CALL, NODE_FUN_DEF, reverse_search(), TC::str_val, TC::type, and TC::x.
Referenced by nasl_lint().
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).
Definition at line 190 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::link, list_cmp(), nasl_get_filename(), nasl_name, nasl_set_filename(), NODE_FUN_CALL, NODE_FUN_DEF, TC::str_val, TC::type, and TC::x.
Referenced by nasl_lint().
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.
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 352 of file lint.c.
References EXPR_INCR, EXPR_NOT, FAKE_CELL, struct_lex_ctxt::line_nb, TC::line_nb, TC::link, list_cmp(), nasl_perror(), NODE_AFF, NODE_ARRAY_EL, NODE_DECL, NODE_FOREACH, NODE_FUN_DEF, NODE_GLOBAL, NODE_LOCAL, NODE_PLUS_EQ, NODE_VAR, TC::str_val, TC::type, and TC::x.
Referenced by nasl_lint().
void print_uncall_files | ( | gpointer | filename, |
gpointer | lexic | ||
) |
It shows a msg for unused included files.
[in] | filename | Filename of the not used inc file. |
[in] | lexic | nasl context. |
Definition at line 174 of file lint.c.
References nasl_perror().
Referenced by nasl_lint().
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 neested and defined function but never called.
Definition at line 107 of file lint.c.
References st_func_info::caller_file, st_func_info::caller_func, st_func_info::func_name, list_cmp1(), and nasl_name.
Referenced by nasl_lint_call().
char* nasl_name |
Definition at line 46 of file lint.c.
Referenced by nasl_lint(), nasl_lint_def(), and reverse_search().