OpenVAS Scanner 23.23.1
lint.c File Reference
#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>

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_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_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_cellvalidate_script_xref (lex_ctxt *lexic, tree_cell *st)
 Validates parameters of a script_xref function call.
static tree_cellvalidate_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_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_tree)
 Check if a called function was defined.
static 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.
static tree_cellmake_call_func_list (lex_ctxt *lexic, tree_cell *st, GSList **called_funcs)
 Make a list of all called functions.
static tree_cellcheck_description_block_xref (lex_ctxt *lexic, tree_cell *st)
 Sanity check of the script_xref parameters in the description block.
static tree_cellcheck_description_block (lex_ctxt *lexic, tree_cell *st)
 Sanity check of the description block.
static tree_cellfind_description_block (lex_ctxt *lexic, tree_cell *st)
 Sanity check of the description block.
tree_cellnasl_lint (lex_ctxt *lexic, tree_cell *st)
 Search for errors in a nasl script.

Variables

char * nasl_name
int errors_cnt
int features = 0

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

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

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

◆ check_description_block()

tree_cell * check_description_block ( lex_ctxt * lexic,
tree_cell * st )
static

Sanity check of the description block.

Returns
FAKE_CELL if success, NULL otherwise.

◆ check_description_block_xref()

tree_cell * check_description_block_xref ( lex_ctxt * lexic,
tree_cell * st )
static

Sanity check of the script_xref parameters in the description block.

◆ find_description_block()

tree_cell * find_description_block ( lex_ctxt * lexic,
tree_cell * st )
static

Sanity check of the description block.

Returns
pointer to the description block tree cell.

◆ free_list_func()

void free_list_func ( func_info * data)
static

Free a func_info structure.

Parameters
[in]defined_varList with all defined variables

◆ get_argument_by_name()

char * get_argument_by_name ( tree_cell * st,
char * name )
static

Checks if a given Arguments is within a given Argument List.

Parameters
stArgument List, should be of Type NODE_ARG
nameName of the Argument to search for
Returns
char* Value of the given Argument name

◆ get_errors_cnt()

int get_errors_cnt ( )
static

◆ inc_errors_cnt()

void inc_errors_cnt ( )
static

◆ init_errors_cnt()

void init_errors_cnt ( )
static

◆ is_deffunc_used()

int is_deffunc_used ( const char * funcname,
const char * filename,
GSList * def_func_tree )
static

Returns 1 if the function is at least used once by another caller than filename otherwise 0.

◆ list_cmp()

gint list_cmp ( gconstpointer lelem,
gconstpointer data )
static

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

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

Make a list of all called functions.

◆ nasl_lint()

tree_cell * nasl_lint ( lex_ctxt * lexic,
tree_cell * st )

Search for errors in a nasl script.

Parameters
[in]lexicnasl context.
[in]ststructure tree of a nasl script.
Returns
FAKE_CELL if no error was found, otherwise NULL or tree_cell which has number of errors as x.i_val.

◆ 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_tree )
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.

◆ 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_tree )
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).

◆ 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 )
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.

◆ nasl_lint_feature_flags()

void nasl_lint_feature_flags ( int flag)

◆ print_uncall_files()

void print_uncall_files ( gpointer filename,
gpointer lexic )
static

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_tree,
GSList * finfo )
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.

Returns
1 if the function is needed, 0 otherwise.

◆ validate_function()

tree_cell * validate_function ( lex_ctxt * lexic,
tree_cell * st )
static

Validate functions.

Parameters
lexic
st
Returns
tree_cell * NULL if it is invalid, FAKE_CELL if it is valid

◆ validate_script_xref()

tree_cell * validate_script_xref ( lex_ctxt * lexic,
tree_cell * st )
static

Validates parameters of a script_xref function call.

Parameters
lexic
stFunction Parameters should be of type NODE_ARG
Returns
tree_cell*

Variable Documentation

◆ errors_cnt

int errors_cnt

◆ features

int features = 0

◆ nasl_name

char* nasl_name