OpenVAS Libraries  9.0.3
nasl_tree.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TC
 

Macros

#define FAKE_CELL   ((void*)1)
 
#define EXIT_CELL   ((void*)2)
 

Typedefs

typedef struct TC tree_cell
 

Enumerations

enum  node_type {
  NODE_EMPTY = 0, NODE_IF_ELSE, NODE_INSTR_L, NODE_FOR,
  NODE_WHILE, NODE_FOREACH, NODE_REPEAT_UNTIL, NODE_REPEATED,
  NODE_FUN_DEF, NODE_FUN_CALL, NODE_DECL, NODE_ARG,
  NODE_RETURN, NODE_BREAK, NODE_CONTINUE, NODE_ARRAY_EL,
  NODE_AFF, NODE_VAR, NODE_LOCAL, NODE_GLOBAL,
  NODE_PLUS_EQ, NODE_MINUS_EQ, NODE_MULT_EQ, NODE_DIV_EQ,
  NODE_MODULO_EQ, NODE_L_SHIFT_EQ, NODE_R_SHIFT_EQ, NODE_R_USHIFT_EQ,
  EXPR_AND, EXPR_OR, EXPR_NOT, EXPR_PLUS,
  EXPR_MINUS, EXPR_U_MINUS, EXPR_MULT, EXPR_DIV,
  EXPR_MODULO, EXPR_EXPO, EXPR_BIT_AND, EXPR_BIT_OR,
  EXPR_BIT_XOR, EXPR_BIT_NOT, EXPR_INCR, EXPR_DECR,
  EXPR_L_SHIFT, EXPR_R_SHIFT, EXPR_R_USHIFT, COMP_MATCH,
  COMP_NOMATCH, COMP_RE_MATCH, COMP_RE_NOMATCH, COMP_LT,
  COMP_LE, COMP_EQ, COMP_NE, COMP_GT,
  COMP_GE, CONST_INT, CONST_STR, CONST_DATA,
  CONST_REGEX, ARRAY_ELEM, REF_VAR, REF_ARRAY,
  DYN_ARRAY
}
 

Functions

tree_cellalloc_tree_cell (int, char *)
 
tree_cellalloc_expr_cell (int, int, tree_cell *, tree_cell *)
 
tree_cellalloc_RE_cell (int, int, tree_cell *, char *)
 
tree_cellalloc_typed_cell (int)
 
int nasl_is_leaf (const tree_cell *)
 
char * get_line_nb (const tree_cell *)
 
tree_celldup_cell (const tree_cell *)
 
void nasl_dump_tree (const tree_cell *)
 
void ref_cell (tree_cell *)
 
void deref_cell (tree_cell *)
 
const char * nasl_type_name (int)
 
int cell_type (const tree_cell *)
 
char * dump_cell_val (const tree_cell *)
 

Macro Definition Documentation

◆ EXIT_CELL

#define EXIT_CELL   ((void*)2)

Definition at line 121 of file nasl_tree.h.

◆ FAKE_CELL

#define FAKE_CELL   ((void*)1)

Definition at line 120 of file nasl_tree.h.

Typedef Documentation

◆ tree_cell

typedef struct TC tree_cell

Enumeration Type Documentation

◆ node_type

enum node_type
Enumerator
NODE_EMPTY 
NODE_IF_ELSE 
NODE_INSTR_L 
NODE_FOR 
NODE_WHILE 
NODE_FOREACH 
NODE_REPEAT_UNTIL 
NODE_REPEATED 
NODE_FUN_DEF 
NODE_FUN_CALL 
NODE_DECL 
NODE_ARG 
NODE_RETURN 
NODE_BREAK 
NODE_CONTINUE 
NODE_ARRAY_EL 
NODE_AFF 
NODE_VAR 
NODE_LOCAL 
NODE_GLOBAL 
NODE_PLUS_EQ 
NODE_MINUS_EQ 
NODE_MULT_EQ 
NODE_DIV_EQ 
NODE_MODULO_EQ 
NODE_L_SHIFT_EQ 
NODE_R_SHIFT_EQ 
NODE_R_USHIFT_EQ 
EXPR_AND 
EXPR_OR 
EXPR_NOT 
EXPR_PLUS 
EXPR_MINUS 
EXPR_U_MINUS 
EXPR_MULT 
EXPR_DIV 
EXPR_MODULO 
EXPR_EXPO 
EXPR_BIT_AND 
EXPR_BIT_OR 
EXPR_BIT_XOR 
EXPR_BIT_NOT 
EXPR_INCR 
EXPR_DECR 
EXPR_L_SHIFT 
EXPR_R_SHIFT 
EXPR_R_USHIFT 
COMP_MATCH 
COMP_NOMATCH 
COMP_RE_MATCH 
COMP_RE_NOMATCH 
COMP_LT 
COMP_LE 
COMP_EQ 
COMP_NE 
COMP_GT 
COMP_GE 
CONST_INT 
CONST_STR 
CONST_DATA 
CONST_REGEX 
ARRAY_ELEM 
REF_VAR 
REF_ARRAY 
DYN_ARRAY 

Definition at line 23 of file nasl_tree.h.

24 {
25  NODE_EMPTY = 0,
26  NODE_IF_ELSE, /* [0] = cond, [1] = if_block, [2] = else_block */
27  NODE_INSTR_L, /* Block. [0] = first instr, [1] = tail */
28  NODE_FOR, /* [0] = start expr, [1] = cond, [2] = end_expr, [3] = block */
29  NODE_WHILE, /* [0] = cond, [1] = block */
32  NODE_REPEATED, /* [0] = func call, [1] = repeat nb */
33  NODE_FUN_DEF, /* [0] = argdecl, [1] = block */
34  NODE_FUN_CALL, /* [0] = arglist */
35  NODE_DECL, /* [0] = next arg in list */
36  NODE_ARG, /* val = name can be NULL, [0] = val, [1] = next arg */
37  NODE_RETURN, /* ret val */
38  NODE_BREAK,
40 
41  NODE_ARRAY_EL, /* val = array name, [0] = index */
42  NODE_AFF, /* [0] = lvalue, [1] = rvalue */
43  NODE_VAR, /* val = variable name */
44  NODE_LOCAL, /* [0] = argdecl */
46 
52 
56 
57  EXPR_AND,
58  EXPR_OR,
59  EXPR_NOT,
60 
61  EXPR_PLUS,
62  EXPR_MINUS,
64  EXPR_MULT,
65  EXPR_DIV,
67  EXPR_EXPO,
68 
73  EXPR_INCR,
74  EXPR_DECR,
78 
79  COMP_MATCH,
83 
84  COMP_LT,
85  COMP_LE,
86  COMP_EQ,
87  COMP_NE,
88  COMP_GT,
89  COMP_GE,
90 
91  CONST_INT,
92  CONST_STR, /* "impure" string */
93 
94  CONST_DATA, /* binary data / "pure" string */
95  CONST_REGEX, /* Compiled regex */
96 
97  ARRAY_ELEM, /* val = char index or NULL if integer,
98  * [0] = value, [1] = next element */
99  /* For exec only */
100  REF_VAR,
101  REF_ARRAY,
102  DYN_ARRAY
103 };

Function Documentation

◆ alloc_expr_cell()

tree_cell* alloc_expr_cell ( int  ,
int  ,
tree_cell ,
tree_cell  
)

Definition at line 86 of file nasl_tree.c.

87 {
88  tree_cell *c = alloc_tree_cell (lnb, NULL);
89  c->type = t;
90  c->link[0] = l;
91  c->link[1] = r;
92  return c;
93 }
struct TC * link[4]
Definition: nasl_tree.h:117
short type
Definition: nasl_tree.h:107
Definition: nasl_tree.h:105
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), TC::link, and TC::type.

Here is the call graph for this function:

◆ alloc_RE_cell()

tree_cell* alloc_RE_cell ( int  ,
int  ,
tree_cell ,
char *   
)

Definition at line 61 of file nasl_tree.c.

62 {
63  regex_t *re = g_malloc0 (sizeof (regex_t));
64  int e;
65 
66  tree_cell *c = alloc_tree_cell (lnb, NULL);
67  c->type = t; /* We could check the type... */
68  c->link[0] = l;
69  c->link[1] = FAKE_CELL;
70  e = regcomp (re, re_str, REG_EXTENDED | REG_NOSUB | REG_ICASE);
71  if (!e)
72  c->x.ref_val = re;
73  else
74  {
75  char errbuf[100];
76  regerror (e, re, errbuf, sizeof (errbuf));
77  nasl_perror (NULL, "Line %d: Cannot compile regex: %s (error %d: %s)\n",
78  lnb, re_str, e, errbuf);
79  g_free (re);
80  }
81  g_free (re_str);
82  return c;
83 }
#define FAKE_CELL
Definition: nasl_tree.h:120
struct TC * link[4]
Definition: nasl_tree.h:117
short type
Definition: nasl_tree.h:107
void * ref_val
Definition: nasl_tree.h:115
union TC::@7 x
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), FAKE_CELL, TC::link, nasl_perror(), TC::ref_val, TC::type, and TC::x.

Here is the call graph for this function:

◆ alloc_tree_cell()

tree_cell* alloc_tree_cell ( int  ,
char *   
)

Definition at line 37 of file nasl_tree.c.

38 {
39  tree_cell *p = g_malloc0 (sizeof (tree_cell));
40  int i;
41 
42  p->type = 0;
43  p->size = 0;
44  p->line_nb = lnb;
45  p->x.str_val = s;
46  p->ref_count = 1;
47  for (i = 0; i < 4; i++)
48  p->link[i] = NULL;
49  return p;
50 }
struct TC * link[4]
Definition: nasl_tree.h:117
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
short ref_count
Definition: nasl_tree.h:109
short line_nb
Definition: nasl_tree.h:108
union TC::@7 x
Definition: nasl_tree.h:105
int size
Definition: nasl_tree.h:110

References TC::line_nb, TC::link, TC::ref_count, TC::size, TC::str_val, TC::type, and TC::x.

Referenced by alloc_expr_cell(), alloc_RE_cell(), alloc_typed_cell(), cgibin(), copy_ref_array(), dup_cell(), forge_icmp_v6_packet(), forge_ip_packet(), forge_ipv6_packet(), forge_tcp_packet(), forge_tcp_v6_packet(), get_host_ip(), get_host_open_port(), get_hostname(), get_icmp_element(), get_icmp_v6_element(), get_ip_element(), get_ipv6_element(), get_kb_item(), get_kb_list(), get_port_state(), get_port_transport(), get_tcp_element(), get_tcp_v6_element(), get_udp_element(), get_udp_port_state(), get_udp_v6_element(), insert_ipv6_options(), nasl_bf_cbc(), nasl_bn_random(), nasl_chomp(), nasl_crap(), nasl_dec2str(), nasl_defined_func(), nasl_dh_compute_key(), nasl_dh_generate_key(), nasl_display(), nasl_do_exit(), nasl_egrep(), nasl_end_denial(), nasl_ereg(), nasl_eregmatch(), nasl_ftp_get_pasv_address(), nasl_ftp_log_in(), nasl_get_sign(), nasl_get_sock_info(), nasl_gunzip(), nasl_gzip(), nasl_hex(), nasl_hexstr(), nasl_incr_variable(), nasl_insert_hexzeros(), nasl_insstr(), nasl_int(), nasl_islocalhost(), nasl_islocalnet(), nasl_isnull(), nasl_keyexchg(), nasl_keys(), nasl_lm_owf_gen(), nasl_make_array(), nasl_make_list(), nasl_match(), nasl_max_index(), nasl_ntlm2_response(), nasl_ntlm_response(), nasl_ntlmv1_hash(), nasl_ntlmv2_hash(), nasl_ntlmv2_response(), nasl_ntv2_owf_gen(), nasl_open_sock_udp(), nasl_ord(), nasl_pcap_next(), nasl_pem_to(), nasl_rand(), nasl_rawstring(), nasl_read_var_ref(), nasl_recv_line(), nasl_rsa_private_decrypt(), nasl_rsa_public_decrypt(), nasl_rsa_public_encrypt(), nasl_rsa_sign(), nasl_scanner_get_port(), nasl_send_capture(), nasl_send_v6packet(), nasl_smb_close(), nasl_smb_connect(), nasl_smb_file_group_sid(), nasl_smb_file_owner_sid(), nasl_smb_file_SDDL(), nasl_smb_file_trustee_rights(), nasl_smb_versioninfo(), nasl_socket_get_cert(), nasl_socket_get_ssl_ciphersuite(), nasl_socket_get_ssl_compression(), nasl_socket_get_ssl_session_id(), nasl_socket_get_ssl_version(), nasl_socket_negotiate_ssl(), nasl_split(), nasl_strcat(), nasl_string(), nasl_strlen(), nasl_strstr(), nasl_substr(), nasl_target_is_ipv6(), nasl_this_host(), nasl_this_host_name(), nasl_tolower(), nasl_toupper(), nasl_typeof(), nasl_win_cmd_exec(), nasl_wmi_close(), nasl_wmi_connect(), nasl_wmi_connect_reg(), nasl_wmi_connect_rsop(), nasl_wmi_query(), nasl_wmi_query_rsop(), nasl_wmi_reg_create_key(), nasl_wmi_reg_delete_key(), nasl_wmi_reg_enum_key(), nasl_wmi_reg_enum_value(), nasl_wmi_reg_get_bin_val(), nasl_wmi_reg_get_dword_val(), nasl_wmi_reg_get_ex_string_val(), nasl_wmi_reg_get_mul_string_val(), nasl_wmi_reg_get_qword_val(), nasl_wmi_reg_get_sz(), nasl_wmi_reg_set_dword_val(), nasl_wmi_reg_set_ex_string_val(), nasl_wmi_reg_set_qword_val(), nasl_wmi_reg_set_string_val(), nasl_wmi_versioninfo(), safe_checks(), scan_phase(), script_get_preference(), script_get_preference_file_content(), set_ip_elements(), set_ipv6_elements(), and var2cell().

◆ alloc_typed_cell()

◆ cell_type()

int cell_type ( const tree_cell )

Definition at line 481 of file nasl_tree.c.

482 {
483  if (c == NULL || c == FAKE_CELL)
484  return 0;
485  else
486  return c->type;
487 }
#define FAKE_CELL
Definition: nasl_tree.h:120

References FAKE_CELL, and TC::type.

Referenced by cell_cmp().

Here is the caller graph for this function:

◆ deref_cell()

void deref_cell ( tree_cell )

Definition at line 202 of file nasl_tree.c.

203 {
204  if (c == NULL || c == FAKE_CELL)
205  return;
206  if (--c->ref_count <= 0)
207  free_tree (c);
208 }
#define FAKE_CELL
Definition: nasl_tree.h:120

References FAKE_CELL, and TC::ref_count.

Referenced by cell2atom(), cell_cmp(), exec_nasl_script(), free_lex_ctxt(), make_array_from_elems(), nasl_clean_ctx(), nasl_display(), nasl_return(), and nasl_start_denial().

Here is the caller graph for this function:

◆ dump_cell_val()

char* dump_cell_val ( const tree_cell )

Definition at line 301 of file nasl_tree.c.

302 {
303  static char txt[80];
304 
305  if (c == NULL)
306  return "NULL";
307  else if (c == FAKE_CELL)
308  return "FAKE";
309  else
310  switch (c->type)
311  {
312  case CONST_INT:
313  snprintf (txt, sizeof (txt), "%ld", c->x.i_val);
314  break;
315  case CONST_STR:
316  case CONST_DATA: /* Beurk (English: Yuck) */
317  if (c->size >= sizeof (txt) + 2)
318  {
319  snprintf (txt, sizeof (txt), "\"%s", c->x.str_val);
320  strcpy (txt + (sizeof (txt) - 5), "...\"");
321  }
322  else
323  snprintf (txt, sizeof (txt), "\"%s\"", c->x.str_val);
324  break;
325  default:
326  snprintf (txt, sizeof (txt), "???? (%s)", nasl_type_name (c->type));
327  break;
328  }
329  return txt;
330 }
#define FAKE_CELL
Definition: nasl_tree.h:120
const char * nasl_type_name(int t)
Definition: nasl_tree.c:420

References CONST_DATA, CONST_INT, CONST_STR, FAKE_CELL, TC::i_val, nasl_type_name(), TC::size, TC::str_val, TC::type, and TC::x.

Here is the call graph for this function:

◆ dup_cell()

tree_cell* dup_cell ( const tree_cell )

Definition at line 96 of file nasl_tree.c.

97 {
98  tree_cell *r;
99  int i;
100 
101  if (tc == NULL)
102  return NULL;
103  else if (tc == FAKE_CELL)
104  return FAKE_CELL;
105 
106  r = alloc_tree_cell (tc->line_nb, NULL);
107  r->type = tc->type;
108  r->size = tc->size;
109  switch (tc->type)
110  {
111  case CONST_STR:
112  case CONST_DATA:
113  r->x.str_val = g_malloc0 (tc->size + 1);
114  memcpy (r->x.str_val, tc->x.str_val, tc->size);
115  break;
116  default:
117  r->x = tc->x;
118  break;
119  }
120 
121  for (i = 0; i < 4; i++)
122  r->link[i] = dup_cell (tc->link[i]);
123  return r;
124 }
#define FAKE_CELL
Definition: nasl_tree.h:120
struct TC * link[4]
Definition: nasl_tree.h:117
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
Definition: nasl_tree.h:105
tree_cell * dup_cell(const tree_cell *tc)
Definition: nasl_tree.c:96
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, CONST_STR, dup_cell(), FAKE_CELL, TC::line_nb, TC::link, TC::size, TC::str_val, TC::type, and TC::x.

Referenced by dup_cell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_line_nb()

char* get_line_nb ( const tree_cell )

Definition at line 452 of file nasl_tree.c.

453 {
454  static char txt[32];
455  if (c == NULL || c == FAKE_CELL || c->line_nb <= 0)
456  return "";
457  snprintf (txt, sizeof (txt), " at or near line %d ", c->line_nb);
458  return txt;
459 }
#define FAKE_CELL
Definition: nasl_tree.h:120

References FAKE_CELL, and TC::line_nb.

Referenced by nasl_incr_variable(), and nasl_read_var_ref().

Here is the caller graph for this function:

◆ nasl_dump_tree()

void nasl_dump_tree ( const tree_cell )

Definition at line 439 of file nasl_tree.c.

440 {
441  printf ("^^^^ %p ^^^^^\n", c);
442  if (c == NULL)
443  puts ("NULL CELL");
444  else if (c == FAKE_CELL)
445  puts ("FAKE CELL");
446  else
447  dump_tree (c, 0, 0);
448  printf ("vvvvvvvvvvvvvvvvvv\n");
449 }
#define FAKE_CELL
Definition: nasl_tree.h:120

References FAKE_CELL.

Referenced by dump_ctxt(), exec_nasl_script(), nasl_clean_ctx(), nasl_exec(), nasl_func_call(), and ref_cell().

Here is the caller graph for this function:

◆ nasl_is_leaf()

int nasl_is_leaf ( const tree_cell )

Definition at line 463 of file nasl_tree.c.

464 {
465  if (pc == NULL || pc == FAKE_CELL)
466  return 1;
467  switch (pc->type)
468  {
469  case CONST_INT:
470  case CONST_STR:
471  case CONST_DATA:
472  case REF_ARRAY:
473  case DYN_ARRAY:
474  return 1;
475  default:
476  return 0;
477  }
478  /*NOTREACHED*/}
#define FAKE_CELL
Definition: nasl_tree.h:120

References CONST_DATA, CONST_INT, CONST_STR, DYN_ARRAY, FAKE_CELL, REF_ARRAY, and TC::type.

◆ nasl_type_name()

const char* nasl_type_name ( int  )

Definition at line 420 of file nasl_tree.c.

421 {
422  static char txt4[4][32]; /* This function may be called 4 times in the same expression */
423  static int i = 0;
424  char *txt;
425 
426  if (++i > 4)
427  i = 0;
428  txt = txt4[i];
429 
430  if (t >= 0 && t < sizeof (node_names) / sizeof (node_names[0]))
431  snprintf (txt, 32, "%s (%d)", node_names[t], t);
432  else
433  snprintf (txt, 32, "*UNKNOWN* (%d)", t);
434  return txt;
435 }

Referenced by dump_cell_val(), make_array_from_elems(), and nasl_affect().

Here is the caller graph for this function:

◆ ref_cell()

void ref_cell ( tree_cell )

Definition at line 188 of file nasl_tree.c.

189 {
190  if (c == NULL || c == FAKE_CELL)
191  return;
192  c->ref_count++;
193  if (c->ref_count < 0)
194  {
195  nasl_perror (NULL, "ref_cell: ref count is negative!\n");
196  nasl_dump_tree (c);
197  abort ();
198  }
199 }
#define FAKE_CELL
Definition: nasl_tree.h:120
void nasl_dump_tree(const tree_cell *c)
Definition: nasl_tree.c:439
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94

References FAKE_CELL, nasl_dump_tree(), nasl_perror(), and TC::ref_count.

Referenced by cell2atom(), nasl_exec(), and nasl_return().

Here is the call graph for this function:
Here is the caller graph for this function: