OpenVAS Scanner  6.0.0~git
Data Structures | Macros | Typedefs | Functions | Variables
lint.c File Reference
#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>

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_three, 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_cellnasl_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_three)
 Loads all defined functions. Also, It constructs a three of called functions to help recognize a not defined function which is never called (nested functions). More...
 
tree_cellnasl_lint_call (lex_ctxt *lexic, tree_cell *st, GHashTable **include_files, GHashTable **func_fnames_tab, gchar *err_fname, GSList **called_funcs, GSList **def_func_three)
 Check if a called function was defined. More...
 
tree_cellnasl_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_cellmake_call_func_list (lex_ctxt *lexic, tree_cell *st, GSList **called_funcs)
 Make a list of all called functions. More...
 
tree_cellnasl_lint (lex_ctxt *lexic, tree_cell *st)
 Search for erros in a nasl script. More...
 

Variables

char * nasl_name
 

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib nasl"

GLib logging domain.

Typedef Documentation

◆ func_info

typedef struct st_func_info func_info

Define struct to store information about a called function.

Function Documentation

◆ add_predef_varname()

void add_predef_varname ( GSList **  defined_var)

Add keywords to the varnames list.

Parameters
[in,out]defined_varList with all defined variables

◆ check_called_files()

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.

Parameters
[in]keyElement key of GHashTable.
[in]valueElement value for a key of GHashTable.
[in]unusedfilesList with unused .inc files.

◆ free_list_func()

void free_list_func ( func_info data)

Free a func_info structure.

Parameters
[in]defined_varList with all defined variables

◆ list_cmp()

gint list_cmp ( gconstpointer  lelem,
gconstpointer  data 
)

This function is called by g_slist_find_custom.

Parameters
[in]lelemElement of GSList.
[in]datastr to be found in the list.
Returns
0 on success, non 0 otherwise.

◆ list_cmp1()

gint list_cmp1 ( gconstpointer  lelem,
gconstpointer  data 
)

This function is called by g_slist_find_custom.

Parameters
[in]lelemElement of GSList.
[in]datafunc_info structure to be found.
Returns
0 on success, non 0 otherwise.

◆ make_call_func_list()

tree_cell* make_call_func_list ( lex_ctxt lexic,
tree_cell st,
GSList **  called_funcs 
)

Make a list of all called functions.

◆ nasl_lint()

tree_cell* nasl_lint ( lex_ctxt lexic,
tree_cell st 
)

Search for erros in a nasl script.

Parameters
[in]lexicnasl context.
[in]ststructure three of a nasl script.
Returns
FAKE_CELL if no error was found, NULL otherwise.

◆ nasl_lint_call()

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_three 
)

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.

◆ nasl_lint_def()

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_three 
)

Loads all defined functions. Also, It constructs a three of called functions to help recognize a not defined function which is never called (nested functions).

◆ nasl_lint_defvar()

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.

◆ print_uncall_files()

void print_uncall_files ( gpointer  filename,
gpointer  lexic 
)

It shows a msg for unused included files.

Parameters
[in]filenameFilename of the not used inc file.
[in]lexicnasl context.

◆ reverse_search()

gint reverse_search ( GSList **  def_func_three,
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.

Returns
1 if the function is needed, 0 otherwise.

Variable Documentation

◆ nasl_name

char* nasl_name