OpenVAS Scanner 23.40.3
nasl_lex_ctxt.h File Reference
#include <glib.h>
#include "../misc/scanneraux.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include "nasl_func.h"
Include dependency graph for nasl_lex_ctxt.h:

Go to the source code of this file.

Data Structures

struct  struct_lex_ctxt

Macros

#define NASL_COMPAT_LEX_CTXT   "NASL compat lex context"

Typedefs

typedef struct struct_lex_ctxt lex_ctxt

Functions

lex_ctxtinit_empty_lex_ctxt (void)
void free_lex_ctxt (lex_ctxt *)
void dump_ctxt (lex_ctxt *)
nasl_funcget_func_ref_by_name (lex_ctxt *, const char *)
tree_celldecl_nasl_func (lex_ctxt *, tree_cell *, int)
nasl_funcinsert_nasl_func (lex_ctxt *, const char *, tree_cell *, int)
tree_cellnasl_func_call (lex_ctxt *, const nasl_func *, tree_cell *)
tree_cellget_variable_by_name (lex_ctxt *, const char *)
tree_cellget_array_elem (lex_ctxt *, const char *, tree_cell *)
anon_nasl_varadd_numbered_var_to_ctxt (lex_ctxt *, int, tree_cell *)
named_nasl_varadd_named_var_to_ctxt (lex_ctxt *, const char *, tree_cell *)
tree_cellnasl_read_var_ref (lex_ctxt *, tree_cell *)
tree_cellnasl_incr_variable (lex_ctxt *, tree_cell *, int, int)
tree_cellnasl_return (lex_ctxt *, tree_cell *)
tree_celldecl_local_variables (lex_ctxt *, tree_cell *)
tree_celldecl_global_variables (lex_ctxt *, tree_cell *)
tree_cellcell2atom (lex_ctxt *, tree_cell *)
long int get_int_var_by_num (lex_ctxt *, int, int)
char * get_str_var_by_num (lex_ctxt *, int)
long int get_int_var_by_name (lex_ctxt *, const char *, int)
char * get_str_var_by_name (lex_ctxt *, const char *)
long int get_var_size_by_name (lex_ctxt *, const char *)
int get_var_type_by_name (lex_ctxt *, const char *)
long int get_var_size_by_num (lex_ctxt *, int)
int get_var_type_by_num (lex_ctxt *, int)
 Returns NASL variable/cell type, VAR2_UNDEF if value is NULL.

Macro Definition Documentation

◆ NASL_COMPAT_LEX_CTXT

#define NASL_COMPAT_LEX_CTXT   "NASL compat lex context"

Definition at line 43 of file nasl_lex_ctxt.h.

Typedef Documentation

◆ lex_ctxt

typedef struct struct_lex_ctxt lex_ctxt

Function Documentation

◆ add_named_var_to_ctxt()

named_nasl_var * add_named_var_to_ctxt ( lex_ctxt * lexic,
const char * name,
tree_cell * val )

Definition at line 810 of file nasl_var.c.

811 {
812 int h = hash_str (name);
814
815 /* Duplicated code ? */
816 for (v = lexic->ctx_vars.hash_elt[h]; v != NULL; v = v->next_var)
817 if (v->var_name != NULL && strcmp (name, v->var_name) == 0)
818 {
819 if (val != NULL)
820 nasl_perror (lexic, "Cannot add existing variable %s\n", name);
821 return NULL;
822 }
824 if (v == NULL)
825 return NULL;
826 v->next_var = lexic->ctx_vars.hash_elt[h];
827 lexic->ctx_vars.hash_elt[h] = v;
828 return v;
829 }
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition nasl_debug.c:105
const char * name
Definition nasl_init.c:440
const char * val
Definition nasl_init.c:441
static int hash_str(const char *s)
Definition nasl_var.c:37
static named_nasl_var * create_named_var(const char *name, tree_cell *val)
Definition nasl_var.c:719
struct st_n_nasl_var named_nasl_var
char * var_name
Definition nasl_var.h:58
struct st_n_nasl_var * next_var
Definition nasl_var.h:62
struct st_n_nasl_var ** hash_elt
Definition nasl_var.h:36
nasl_array ctx_vars

References create_named_var(), struct_lex_ctxt::ctx_vars, st_nasl_array::hash_elt, hash_str(), name, nasl_perror(), st_n_nasl_var::next_var, val, and st_n_nasl_var::var_name.

Referenced by decl_local_variables(), exec_nasl_script(), init_nasl_library(), and nasl_func_call().

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

◆ add_numbered_var_to_ctxt()

anon_nasl_var * add_numbered_var_to_ctxt ( lex_ctxt * lexic,
int num,
tree_cell * val )

Definition at line 781 of file nasl_var.c.

782 {
783 anon_nasl_var *v;
784 nasl_array *a = &lexic->ctx_vars;
785
786 if (a->max_idx > num)
787 {
788 v = a->num_elt[num];
789 if (v != NULL && v->var_type != VAR2_UNDEF)
790 {
791 if (val != NULL)
792 nasl_perror (lexic, "Cannot add existing variable %d\n", num);
793 return NULL;
794 }
795 free_anon_var (a->num_elt[num]);
796 }
797 else
798 {
799 a->num_elt =
800 g_realloc (a->num_elt, (num + 1) * sizeof (anon_nasl_var *));
801 bzero (a->num_elt + a->max_idx,
802 sizeof (anon_nasl_var *) * (num + 1 - a->max_idx));
803 a->max_idx = num + 1;
804 }
805 a->num_elt[num] = v = create_anon_var (val);
806 return v;
807 }
static anon_nasl_var * create_anon_var(tree_cell *val)
Definition nasl_var.c:740
static void free_anon_var(anon_nasl_var *)
Definition nasl_var.c:384
struct st_a_nasl_var anon_nasl_var
struct st_nasl_array nasl_array
@ VAR2_UNDEF
Definition nasl_var.h:15
struct st_a_nasl_var ** num_elt
Definition nasl_var.h:35

References create_anon_var(), struct_lex_ctxt::ctx_vars, free_anon_var(), st_nasl_array::max_idx, nasl_perror(), st_nasl_array::num_elt, val, VAR2_UNDEF, and st_a_nasl_var::var_type.

Referenced by nasl_func_call().

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

◆ cell2atom()

tree_cell * cell2atom ( lex_ctxt * lexic,
tree_cell * c1 )
Returns
A 'referenced' cell.

Definition at line 194 of file exec.c.

195{
196 tree_cell *c2 = NULL, *ret = NULL;
197 if (c1 == NULL || c1 == FAKE_CELL)
198 return c1;
199
200 switch (c1->type)
201 {
202 case CONST_INT:
203 case CONST_STR:
204 case CONST_DATA:
205 case REF_ARRAY:
206 case DYN_ARRAY:
207 ref_cell (c1);
208 return c1;
209 default:
210 c2 = nasl_exec (lexic, c1);
211 ret = cell2atom (lexic, c2);
212 deref_cell (c2);
213 return ret;
214 }
215}
tree_cell * cell2atom(lex_ctxt *lexic, tree_cell *c1)
Definition exec.c:194
tree_cell * nasl_exec(lex_ctxt *lexic, tree_cell *st)
Execute a parse tree.
Definition exec.c:770
void ref_cell(tree_cell *c)
Definition nasl_tree.c:164
void deref_cell(tree_cell *c)
Definition nasl_tree.c:178
@ CONST_DATA
Definition nasl_tree.h:82
@ DYN_ARRAY
Definition nasl_tree.h:90
@ CONST_STR
Definition nasl_tree.h:80
@ CONST_INT
Definition nasl_tree.h:79
@ REF_ARRAY
Definition nasl_tree.h:89
struct TC tree_cell
#define FAKE_CELL
Definition nasl_tree.h:110
short type
Definition nasl_tree.h:95

References cell2atom(), CONST_DATA, CONST_INT, CONST_STR, deref_cell(), DYN_ARRAY, FAKE_CELL, nasl_exec(), REF_ARRAY, ref_cell(), and TC::type.

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

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

◆ decl_global_variables()

tree_cell * decl_global_variables ( lex_ctxt * lexic,
tree_cell * vars )

Definition at line 771 of file nasl_var.c.

772 {
773 lex_ctxt *c = lexic;
774
775 while (c->up_ctxt != NULL)
776 c = c->up_ctxt;
777 return decl_local_variables (c, vars);
778 }
struct struct_lex_ctxt lex_ctxt
tree_cell * decl_local_variables(lex_ctxt *lexic, tree_cell *vars)
Definition nasl_var.c:758
struct struct_lex_ctxt * up_ctxt

References decl_local_variables(), and struct_lex_ctxt::up_ctxt.

Referenced by nasl_exec().

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

◆ decl_local_variables()

tree_cell * decl_local_variables ( lex_ctxt * lexic,
tree_cell * vars )

Definition at line 758 of file nasl_var.c.

759 {
760 tree_cell *t;
761
762 for (t = vars; t != NULL; t = t->link[0])
763 if (t->x.str_val == NULL)
764 nasl_perror (lexic, "decl_local_variables: null name!\n");
765 else
766 add_named_var_to_ctxt (lexic, t->x.str_val, NULL);
767 return FAKE_CELL;
768 }
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *lexic, const char *name, tree_cell *val)
Definition nasl_var.c:810
struct TC * link[4]
Definition nasl_tree.h:107
union TC::@332262321161220155002104006201360276211317150140 x
char * str_val
Definition nasl_tree.h:103

References add_named_var_to_ctxt(), FAKE_CELL, TC::link, nasl_perror(), TC::str_val, and TC::x.

Referenced by decl_global_variables(), and nasl_exec().

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

◆ decl_nasl_func()

tree_cell * decl_nasl_func ( lex_ctxt * lexic,
tree_cell * decl_node,
int lint_mode )

Definition at line 66 of file nasl_func.c.

67{
68 if (decl_node == NULL || decl_node == FAKE_CELL)
69 {
70 nasl_perror (lexic, "Cannot insert NULL or FAKE cell as function\n");
71 return NULL;
72 }
73
74 if (insert_nasl_func (lexic, decl_node->x.str_val, decl_node, lint_mode)
75 == NULL)
76 return NULL;
77 else
78 return FAKE_CELL;
79}
nasl_func * insert_nasl_func(lex_ctxt *lexic, const char *fname, tree_cell *decl_node, int lint_mode)
Definition nasl_func.c:41

References FAKE_CELL, insert_nasl_func(), nasl_perror(), TC::str_val, and TC::x.

Referenced by nasl_exec(), nasl_lint_call(), and nasl_lint_def().

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

◆ dump_ctxt()

void dump_ctxt ( lex_ctxt * c)

Definition at line 52 of file nasl_lex_ctxt.c.

53{
54 int i;
56
57 printf ("--------<CTXT>--------\n");
58 if (c->fct_ctxt)
59 printf ("Is a function context\n");
60 if (c->up_ctxt == NULL)
61 printf ("Is the top level context\n");
62 if (c->ret_val)
63 {
64 printf ("Return value\n");
66 }
67
68 printf ("Variables:\n");
69 for (i = 0; i < VAR_NAME_HASH; i++)
70 for (v = c->ctx_vars.hash_elt[i]; v != NULL; v = v->next_var)
71 printf ("%s\t", v->var_name);
72 putchar ('\n');
73
74 printf ("----------------------\n");
75}
void nasl_dump_tree(const tree_cell *c)
Definition nasl_tree.c:363
#define VAR_NAME_HASH
Definition nasl_var.h:22
tree_cell * ret_val

References struct_lex_ctxt::ctx_vars, struct_lex_ctxt::fct_ctxt, st_nasl_array::hash_elt, nasl_dump_tree(), st_n_nasl_var::next_var, struct_lex_ctxt::ret_val, struct_lex_ctxt::up_ctxt, st_n_nasl_var::var_name, and VAR_NAME_HASH.

Referenced by nasl_dump_ctxt().

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

◆ free_lex_ctxt()

void free_lex_ctxt ( lex_ctxt * c)

Definition at line 43 of file nasl_lex_ctxt.c.

44{
46 free_array (&c->ctx_vars);
47 g_hash_table_destroy (c->functions);
48 g_free (c);
49}
void free_array(nasl_array *a)
Definition nasl_var.c:339
GHashTable * functions

References struct_lex_ctxt::ctx_vars, deref_cell(), free_array(), struct_lex_ctxt::functions, and struct_lex_ctxt::ret_val.

Referenced by exec_nasl_script(), nasl_func_call(), and nasl_lint().

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

◆ get_array_elem()

tree_cell * get_array_elem ( lex_ctxt * ctxt,
const char * name,
tree_cell * idx )

Definition at line 208 of file nasl_var.c.

209 {
210 named_nasl_var *nv;
211 anon_nasl_var *u, *av, fake_var;
212 tree_cell *tc, idx0;
213
214 /* Fake variable */
215 if (strcmp (name, "_FCT_ANON_ARGS") == 0)
216 {
217 lex_ctxt *c;
218 for (c = ctxt; c != NULL && !c->fct_ctxt; c = c->up_ctxt)
219 ;
220 if (c == NULL)
221 return NULL;
222 fake_var.var_type = VAR2_ARRAY;
223 fake_var.v.v_arr = c->ctx_vars;
224 fake_var.v.v_arr.hash_elt = NULL; /* mask named elements */
225 u = &fake_var;
226 }
227 else
228 {
230 u = &v->u;
231 }
232
233 if (idx == NULL)
234 {
235 /* Treat it as zero */
236 memset (&idx0, '\0', sizeof (idx0));
237 idx = &idx0;
238 idx->type = CONST_INT;
239 }
240
241 switch (u->var_type)
242 {
243 case VAR2_UNDEF:
244 /* We define the array here */
245 u->var_type = VAR2_ARRAY;
246 /* fallthrough */
247 case VAR2_ARRAY:
248 switch (idx->type)
249 {
250 case CONST_INT:
251 av = nasl_get_var_by_num (ctxt, &u->v.v_arr, idx->x.i_val,
252 /* avoid dangling pointers */
253 strcmp (name, "_FCT_ANON_ARGS"));
254 return var2cell (av);
255
256 case CONST_STR:
257 case CONST_DATA:
258 nv = get_var_by_name (&u->v.v_arr, idx->x.str_val);
259 return var2cell (nv != NULL ? &nv->u : NULL);
260
261 default:
262 nasl_perror (ctxt,
263 "get_array_elem: unhandled index type 0x%x for "
264 "variable %s\n",
265 idx->type, name);
266 return NULL;
267 }
268 /*NOTREACHED*/ break;
269
270 case VAR2_INT:
271 nasl_perror (ctxt, "get_array_elem: variable %s is an integer\n", name);
272 return NULL;
273
274 case VAR2_STRING:
275 case VAR2_DATA:
276 if (idx->type == CONST_INT)
277 {
278 int l = u->v.v_str.s_siz;
279
280 if (idx->x.i_val >= l)
281 {
282 nasl_perror (ctxt,
283 "get_array_elem: requesting character after end "
284 "of string %s (%d >= %d)\n",
285 name, idx->x.i_val, l);
286 tc = alloc_expr_cell (idx->line_nb, CONST_DATA /*CONST_STR */,
287 NULL, NULL);
288 tc->x.str_val = g_strdup ("");
289 tc->size = 0;
290 return tc;
291 }
292 else
293 {
294 if (idx->x.i_val < 0)
295 {
296 nasl_perror (ctxt,
297 "get_array_elem: Negative index (%d) passed to "
298 "\"%s\"!\n",
299 idx->x.i_val, name);
300 return NULL;
301 }
302 tc = alloc_expr_cell (idx->line_nb, CONST_DATA /*CONST_STR */,
303 NULL, NULL);
304 tc->x.str_val = g_malloc0 (2);
305 tc->x.str_val[0] = u->v.v_str.s_val[idx->x.i_val];
306 tc->x.str_val[1] = '\0';
307 tc->size = 1;
308 return tc;
309 }
310 }
311 else
312 {
313 nasl_perror (ctxt,
314 "get_array_elem: Cannot use a non integer index"
315 " (type 0x%x) in string. Variable: %s\n",
316 idx->type, name);
317 return NULL;
318 }
319 /*NOTREACHED*/ break;
320
321 default:
322 nasl_perror (ctxt, "Severe bug: unknown variable type 0x%x %s\n",
323 u->var_type, get_line_nb (idx));
324 return NULL;
325 }
326 /*NOTREACHED*/ return NULL;
327 }
tree_cell * alloc_expr_cell(int lnb, int t, tree_cell *l, tree_cell *r)
Definition nasl_tree.c:60
char * get_line_nb(const tree_cell *c)
Definition nasl_tree.c:376
static named_nasl_var * get_var_ref_by_name(lex_ctxt *ctxt, const char *name, int climb)
This function climbs up in the context list.
Definition nasl_var.c:100
named_nasl_var * get_var_by_name(nasl_array *a, const char *s)
Definition nasl_var.c:75
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
Definition nasl_var.c:43
tree_cell * var2cell(anon_nasl_var *v)
Definition nasl_var.c:168
@ VAR2_STRING
Definition nasl_var.h:17
@ VAR2_DATA
Definition nasl_var.h:18
@ VAR2_ARRAY
Definition nasl_var.h:19
@ VAR2_INT
Definition nasl_var.h:16
long int i_val
Definition nasl_tree.h:104
long int size
Definition nasl_tree.h:99
short line_nb
Definition nasl_tree.h:96
nasl_string_t v_str
Definition nasl_var.h:47
nasl_array v_arr
Definition nasl_var.h:49
union st_a_nasl_var::@154137074032032170165360023270032033276061363156 v
struct st_a_nasl_var u
Definition nasl_var.h:56
unsigned char * s_val
Definition nasl_var.h:26
long int s_siz
Definition nasl_var.h:27

References alloc_expr_cell(), CONST_DATA, CONST_INT, CONST_STR, struct_lex_ctxt::ctx_vars, struct_lex_ctxt::fct_ctxt, get_line_nb(), get_var_by_name(), get_var_ref_by_name(), st_nasl_array::hash_elt, TC::i_val, TC::line_nb, name, nasl_get_var_by_num(), nasl_perror(), st_nasl_string::s_siz, st_nasl_string::s_val, TC::size, TC::str_val, TC::type, st_n_nasl_var::u, struct_lex_ctxt::up_ctxt, st_a_nasl_var::v, st_a_nasl_var::v_arr, st_a_nasl_var::v_str, VAR2_ARRAY, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, var2cell(), st_a_nasl_var::var_type, and TC::x.

Referenced by nasl_exec().

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

◆ get_func_ref_by_name()

nasl_func * get_func_ref_by_name ( lex_ctxt * ctxt,
const char * name )

Definition at line 82 of file nasl_func.c.

83{
84 nasl_func *f;
85
86 if ((f = get_func (ctxt, name)))
87 return f;
88 else
89 return NULL;
90}
static nasl_func * get_func(lex_ctxt *ctxt, const char *name)
This function climbs up in the context list and searches for a given.
Definition nasl_func.c:25
struct st_nasl_func nasl_func

References get_func(), and name.

Referenced by exec_nasl_script(), make_call_func_list(), nasl_defined_func(), nasl_exec(), nasl_lint_call(), and nasl_lint_def().

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

◆ get_int_var_by_name()

long int get_int_var_by_name ( lex_ctxt * lexic,
const char * name,
int defval )

Definition at line 1101 of file nasl_var.c.

1102 {
1103 named_nasl_var *v = get_var_ref_by_name (lexic, name, 0);
1104 return var2int (&v->u, defval);
1105 }
static long int var2int(anon_nasl_var *v, int defval)
Definition nasl_var.c:968

References get_var_ref_by_name(), name, st_n_nasl_var::u, and var2int().

Referenced by __attribute__(), _http2_req(), _http_req(), crypt_data(), encrypt_stream_data(), forge_icmp_packet(), forge_icmp_v6_packet(), forge_igmp_packet(), forge_igmp_v6_packet(), forge_ip_packet(), forge_ip_v6_packet(), forge_tcp_packet(), forge_tcp_v6_packet(), forge_udp_packet(), forge_udp_v6_packet(), get_port_transport(), get_tcp_option(), get_tcp_v6_option(), insert_ip_options(), nasl_bn_random(), nasl_close_stream_cipher(), nasl_crap(), nasl_dec2str(), nasl_egrep(), nasl_ereg(), nasl_ereg_replace(), nasl_eregmatch(), nasl_file_read(), nasl_file_seek(), nasl_file_write(), nasl_forge_frame(), nasl_ftp_get_pasv_address(), nasl_ftp_log_in(), nasl_get_sign(), nasl_get_sock_info(), nasl_http2_get_response_code(), nasl_http2_set_custom_header(), nasl_isotime_add(), nasl_localtime(), nasl_match(), nasl_mktime(), nasl_ntlm_response(), nasl_ntlmv2_hash(), nasl_ntlmv2_response(), nasl_open_privileged_socket(), nasl_open_sock_tcp_bufsz(), nasl_pcap_next(), nasl_pread(), nasl_prf(), nasl_rc4_encrypt(), nasl_recv(), nasl_recv_line(), nasl_rsa_private_decrypt(), nasl_rsa_public_encrypt(), nasl_same_host(), nasl_scanner_add_port(), nasl_send(), nasl_send_arp_request(), nasl_send_capture(), nasl_send_frame(), nasl_send_packet(), nasl_send_v6packet(), nasl_smb3kdf(), nasl_smb_close(), nasl_smb_file_group_sid(), nasl_smb_file_owner_sid(), nasl_smb_file_SDDL(), nasl_smb_file_trustee_rights(), nasl_snmpv1v2c_get(), nasl_snmpv3_get_action(), nasl_socket_cert_verify(), nasl_socket_check_ssl_safe_renegotiation(), nasl_socket_get_cert(), nasl_socket_get_ssl_ciphersuite(), nasl_socket_get_ssl_session_id(), nasl_socket_get_ssl_version(), nasl_socket_negotiate_ssl(), nasl_socket_ssl_do_handshake(), nasl_split(), nasl_ssh_connect(), nasl_ssh_request_exec(), nasl_ssh_shell_open(), nasl_ssh_shell_read(), nasl_str_replace(), nasl_tcp_ping(), nasl_tcp_v6_ping(), nasl_wmi_close(), 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(), replace_kb_item(), script_add_preference(), script_get_preference(), security_something(), set_ip_elements(), set_ip_v6_elements(), set_kb_item(), set_kb_item_volatile(), set_tcp_elements(), set_tcp_v6_elements(), set_udp_elements(), and set_udp_v6_elements().

Here is the call graph for this function:

◆ get_int_var_by_num()

long int get_int_var_by_num ( lex_ctxt * lexic,
int num,
int defval )

◆ get_str_var_by_name()

char * get_str_var_by_name ( lex_ctxt * lexic,
const char * name )

Definition at line 1118 of file nasl_var.c.

1119 {
1120 named_nasl_var *v = get_var_ref_by_name (lexic, name, 0);
1121 return (char *) var2str (&v->u);
1122 }
const char * var2str(anon_nasl_var *v)
Definition nasl_var.c:1062

References get_var_ref_by_name(), name, st_n_nasl_var::u, and var2str().

Referenced by __attribute__(), _http2_req(), _http_req(), add_hostname(), crypt_data(), encrypt_stream_data(), forge_icmp_packet(), forge_icmp_v6_packet(), forge_igmp_packet(), forge_igmp_v6_packet(), forge_ip_packet(), forge_ip_v6_packet(), forge_tcp_packet(), forge_tcp_v6_packet(), forge_udp_packet(), forge_udp_v6_packet(), get_hostname_source(), get_icmp_element(), get_icmp_v6_element(), get_ip_element(), get_ip_v6_element(), get_tcp_element(), get_tcp_option(), get_tcp_v6_element(), get_tcp_v6_option(), get_udp_element(), get_udp_v6_element(), insert_ip_options(), insert_tcp_options(), insert_tcp_v6_options(), mpi_from_named_parameter(), nasl_bf_cbc(), nasl_crap(), nasl_dump_frame(), nasl_egrep(), nasl_ereg(), nasl_ereg_replace(), nasl_eregmatch(), nasl_file_open(), nasl_file_write(), nasl_forge_frame(), nasl_ftp_log_in(), nasl_fwrite(), nasl_get_sign(), nasl_gunzip(), nasl_gzip(), nasl_hmac(), nasl_hmac_sha256(), nasl_http2_set_custom_header(), nasl_insert_hexzeros(), nasl_keyexchg(), nasl_load_privkey_param(), nasl_mac(), nasl_match(), nasl_notus(), nasl_ntlm2_response(), nasl_ntlm_response(), nasl_ntlmv1_hash(), nasl_ntlmv2_hash(), nasl_ntlmv2_response(), nasl_ntv2_owf_gen(), nasl_okrb5_add_realm(), nasl_open_sock_tcp_bufsz(), nasl_open_stream_cipher(), nasl_pcap_next(), nasl_pread(), nasl_prf(), nasl_rsa_private_decrypt(), nasl_rsa_public_encrypt(), nasl_rsa_sign(), nasl_scanner_add_port(), nasl_send(), nasl_send_capture(), nasl_send_frame(), nasl_send_packet(), nasl_send_v6packet(), nasl_smb3kdf(), nasl_smb_connect(), nasl_smb_file_group_sid(), nasl_smb_file_owner_sid(), nasl_smb_file_SDDL(), nasl_smb_file_trustee_rights(), nasl_smb_sign(), nasl_snmpv1v2c_get(), nasl_snmpv3_get_action(), nasl_split(), nasl_ssh_connect(), nasl_ssh_login_interactive_pass(), nasl_ssh_request_exec(), nasl_ssh_set_login(), nasl_ssh_shell_write(), nasl_ssh_userauth(), nasl_str_replace(), nasl_update_table_driven_lsc_data(), 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(), replace_kb_item(), resolve_hostname(), resolve_hostname_to_multiple_ips(), script_add_preference(), script_mandatory_keys(), script_tag(), script_xref(), security_something(), set_ip_elements(), set_ip_v6_elements(), set_kb_item(), set_kb_item_volatile(), set_tcp_elements(), set_tcp_v6_elements(), set_udp_elements(), and set_udp_v6_elements().

Here is the call graph for this function:

◆ get_str_var_by_num()

char * get_str_var_by_num ( lex_ctxt * lexic,
int num )

◆ get_var_size_by_name()

long int get_var_size_by_name ( lex_ctxt * lexic,
const char * name )

Definition at line 1138 of file nasl_var.c.

1139 {
1140 named_nasl_var *v = get_var_ref_by_name (lexic, name, 0);
1141 return get_var_size (&v->u);
1142 }
static long int get_var_size(const anon_nasl_var *v)
Definition nasl_var.c:1124

References get_var_ref_by_name(), get_var_size(), name, and st_n_nasl_var::u.

Referenced by __attribute__(), crypt_data(), encrypt_stream_data(), forge_icmp_packet(), forge_icmp_v6_packet(), forge_igmp_packet(), forge_igmp_v6_packet(), forge_ip_packet(), forge_ip_v6_packet(), forge_tcp_packet(), forge_tcp_v6_packet(), forge_udp_packet(), forge_udp_v6_packet(), get_icmp_element(), get_icmp_v6_element(), get_tcp_element(), get_tcp_option(), get_tcp_v6_element(), get_tcp_v6_option(), get_udp_element(), get_udp_v6_element(), insert_ip_options(), insert_tcp_options(), insert_tcp_v6_options(), mpi_from_named_parameter(), nasl_bf_cbc(), nasl_crap(), nasl_dump_frame(), nasl_egrep(), nasl_ereg(), nasl_ereg_replace(), nasl_eregmatch(), nasl_file_write(), nasl_forge_frame(), nasl_fwrite(), nasl_gunzip(), nasl_gzip(), nasl_hmac(), nasl_hmac_sha256(), nasl_insert_hexzeros(), nasl_load_privkey_param(), nasl_mac(), nasl_ntlm2_response(), nasl_ntlm_response(), nasl_ntlmv1_hash(), nasl_ntlmv2_hash(), nasl_ntv2_owf_gen(), nasl_open_stream_cipher(), nasl_prf(), nasl_rsa_sign(), nasl_send(), nasl_send_frame(), nasl_smb3kdf(), nasl_smb_sign(), nasl_split(), nasl_str_replace(), replace_kb_item(), security_something(), set_ip_elements(), set_ip_v6_elements(), set_kb_item(), set_kb_item_volatile(), set_tcp_elements(), set_tcp_v6_elements(), set_udp_elements(), and set_udp_v6_elements().

Here is the call graph for this function:

◆ get_var_size_by_num()

◆ get_var_type_by_name()

int get_var_type_by_name ( lex_ctxt * lexic,
const char * name )

Definition at line 1162 of file nasl_var.c.

1163 {
1164 named_nasl_var *v = get_var_ref_by_name (lexic, name, 0);
1165 return v == NULL ? VAR2_UNDEF : v->u.var_type;
1166 }

References get_var_ref_by_name(), name, st_n_nasl_var::u, VAR2_UNDEF, and st_a_nasl_var::var_type.

Referenced by nasl_open_sock_tcp_bufsz(), nasl_rsa_private_decrypt(), nasl_rsa_public_encrypt(), replace_kb_item(), set_kb_item(), and set_kb_item_volatile().

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

◆ get_var_type_by_num()

int get_var_type_by_num ( lex_ctxt * lexic,
int num )

Returns NASL variable/cell type, VAR2_UNDEF if value is NULL.

Definition at line 1155 of file nasl_var.c.

1156 {
1157 anon_nasl_var *v = get_var_ref_by_num (lexic, num);
1158 return v == NULL ? VAR2_UNDEF : v->var_type;
1159 }

References get_var_ref_by_num(), VAR2_UNDEF, and st_a_nasl_var::var_type.

Referenced by nasl_get_sock_info(), nasl_isnull(), nasl_isotime_is_valid(), nasl_isotime_scan(), nasl_rawstring(), nasl_string(), and nasl_substr().

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

◆ get_variable_by_name()

tree_cell * get_variable_by_name ( lex_ctxt * ctxt,
const char * name )

Definition at line 176 of file nasl_var.c.

177{
178 if (name == NULL)
179 return NULL;
180 /* Broken: Need also code in get_array_elem */
181 if (strcmp (name, "_FCT_ANON_ARGS") == 0)
182 {
184 nasl_array *a = retc->x.ref_val = g_malloc0 (sizeof (nasl_array));
185 copy_array (a, &ctxt->ctx_vars, 0);
186 return retc;
187 }
188 else
189 {
191 return var2cell (&v->u);
192 }
193 /*NOTREACHED*/}
tree_cell * alloc_typed_cell(int typ)
Definition nasl_tree.c:25
static void copy_array(nasl_array *, const nasl_array *, int)
Definition nasl_var.c:493
void * ref_val
Definition nasl_tree.h:105

References alloc_typed_cell(), copy_array(), struct_lex_ctxt::ctx_vars, DYN_ARRAY, get_var_ref_by_name(), name, TC::ref_val, st_n_nasl_var::u, var2cell(), and TC::x.

Referenced by nasl_exec(), nasl_pread(), and security_notus().

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

◆ init_empty_lex_ctxt()

lex_ctxt * init_empty_lex_ctxt ( void )
Todo
Initialization of the library seems intuitively be necessary only once (involves "linking" the nasl functions to c code). Consider a "prototype" context that has to be created only once and of which copies are made when needed.

Definition at line 20 of file nasl_lex_ctxt.c.

21{
22 lex_ctxt *c = g_malloc0 (sizeof (lex_ctxt));
23
24 c->ctx_vars.hash_elt = g_malloc0 (sizeof (named_nasl_var *) * VAR_NAME_HASH);
25 c->ctx_vars.num_elt = NULL;
26 c->ctx_vars.max_idx = 0;
27 c->functions = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
28 (GDestroyNotify) free_func);
29 c->oid = NULL;
30 c->ret_val = NULL;
31 c->fct_ctxt = 0;
32
38
39 return c;
40}
void free_func(nasl_func *f)
Definition nasl_func.c:266
void init_nasl_library(lex_ctxt *)
Adds "built-in" variable and function definitions to a context.
Definition nasl_init.c:515
const char * oid

References struct_lex_ctxt::ctx_vars, struct_lex_ctxt::fct_ctxt, free_func(), struct_lex_ctxt::functions, st_nasl_array::hash_elt, init_nasl_library(), st_nasl_array::max_idx, st_nasl_array::num_elt, struct_lex_ctxt::oid, struct_lex_ctxt::ret_val, and VAR_NAME_HASH.

Referenced by exec_nasl_script(), nasl_func_call(), and nasl_lint().

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

◆ insert_nasl_func()

nasl_func * insert_nasl_func ( lex_ctxt * lexic,
const char * fname,
tree_cell * decl_node,
int lint_mode )

Definition at line 41 of file nasl_func.c.

43{
44 nasl_func *pf;
45
46 if (get_func (lexic, fname))
47 {
48 if (lint_mode == 0)
50 lexic, "insert_nasl_func: function '%s' is already defined\n", fname);
51 return NULL;
52 }
53 pf = g_malloc0 (sizeof (nasl_func));
54 pf->func_name = g_strdup (fname);
55
56 if (decl_node != NULL && decl_node != FAKE_CELL)
57 {
58 pf->block = decl_node->link[1];
59 ref_cell (pf->block);
60 }
61 g_hash_table_insert (lexic->functions, pf->func_name, pf);
62 return pf;
63}
void * block
Definition nasl_func.h:17
char * func_name
Definition nasl_func.h:16

References st_nasl_func::block, FAKE_CELL, st_nasl_func::func_name, struct_lex_ctxt::functions, get_func(), TC::link, nasl_perror(), and ref_cell().

Referenced by decl_nasl_func().

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

◆ nasl_func_call()

tree_cell * nasl_func_call ( lex_ctxt * lexic,
const nasl_func * f,
tree_cell * arg_list )

Definition at line 95 of file nasl_func.c.

96{
97 int nb_u = 0, nb_a = 0;
98 tree_cell *pc = NULL, *pc2 = NULL, *retc = NULL;
99 lex_ctxt *lexic2 = NULL;
100 char *trace_buf = NULL;
101 char *temp_funname = NULL, *tmp_filename = NULL;
102 int trace_buf_len = 0, tn;
103#define TRACE_BUF_SZ 255
104
105 /* 1. Create a new context */
106 lexic2 = init_empty_lex_ctxt ();
107 lexic2->script_infos = lexic->script_infos;
108 lexic2->oid = lexic->oid;
109 lexic2->recv_timeout = lexic->recv_timeout;
110 lexic2->fct_ctxt = 1;
111
112 if (nasl_trace_fp != NULL)
113 {
114 trace_buf = g_malloc0 (TRACE_BUF_SZ);
115 tn = snprintf (trace_buf, TRACE_BUF_SZ, "Call %s(", f->func_name);
116 if (tn > 0)
117 trace_buf_len += tn;
118 }
119
120 for (pc = arg_list; pc != NULL; pc = pc->link[1])
121 if (pc->x.str_val == NULL)
122 nb_u++;
123
124 /*
125 * I should look exactly how unnamed arguments works...
126 * Or maybe I should remove this feature?
127 */
128
129 for (nb_u = 0, pc = arg_list; pc != NULL; pc = pc->link[1])
130 {
131 pc2 = cell2atom (lexic, pc->link[0]);
132 if (pc->x.str_val == NULL)
133 {
134 /* 2. Add unnamed (numbered) variables for unnamed args */
135 if (add_numbered_var_to_ctxt (lexic2, nb_u, pc2) == NULL)
136 goto error;
137 nb_u++;
138 if (nasl_trace_fp != NULL && trace_buf_len < TRACE_BUF_SZ)
139 {
140 tn = snprintf (trace_buf + trace_buf_len,
141 TRACE_BUF_SZ - trace_buf_len, "%s%d: %s",
142 nb_a > 0 ? ", " : "", nb_u, dump_cell_val (pc2));
143 if (tn > 0)
144 trace_buf_len += tn;
145 }
146 nb_a++;
147 }
148 else
149 {
150 /* 3. and add named variables for named args */
151 if (add_named_var_to_ctxt (lexic2, pc->x.str_val, pc2) == NULL)
152 goto error;
153 if (nasl_trace_fp != NULL && trace_buf_len < TRACE_BUF_SZ)
154 {
155 tn = snprintf (trace_buf + trace_buf_len,
156 TRACE_BUF_SZ - trace_buf_len, "%s%s: %s",
157 nb_a > 0 ? ", " : "", pc->x.str_val,
158 dump_cell_val (pc2));
159 if (tn > 0)
160 trace_buf_len += tn;
161 }
162 nb_a++;
163 }
164 deref_cell (pc2);
165 }
166
167 if (nasl_trace_fp != NULL)
168 {
169 if (trace_buf_len < TRACE_BUF_SZ)
170 nasl_trace (lexic, "NASL> %s)\n", trace_buf);
171 else
172 nasl_trace (lexic, "NASL> %s ...)\n", trace_buf);
173 }
174 /* trace_buf freed here because nasl_trace_fp might get set to NULL during the
175 * execution of nasl_func_call and therefore not get freed if we only free in
176 * the previous if block. This is done to make static analyzer happy. */
177 g_free (trace_buf);
178
179 /* 4. Chain new context to old (lexic) */
180 lexic2->up_ctxt = lexic;
181 /* 5. Execute */
182 tmp_filename = g_strdup (nasl_get_filename (NULL));
185 {
186#pragma GCC diagnostic push
187#pragma GCC diagnostic ignored "-Wpedantic"
188 // unless it is arcane system this void casting should work
189 // therefore ignoring pedantic here.
190 tree_cell *(*pf2) (lex_ctxt *) = f->block;
191#pragma GCC diagnostic pop
192 retc = pf2 (lexic2);
193 }
194 else
195 {
196 temp_funname = g_strdup (nasl_get_function_name ());
198 retc = nasl_exec (lexic2, f->block);
199 deref_cell (retc);
200 retc = FAKE_CELL;
201 nasl_set_function_name (temp_funname);
202 g_free (temp_funname);
203 }
204 nasl_set_filename (tmp_filename);
205 g_free (tmp_filename);
206
207 if ((retc == NULL || retc == FAKE_CELL)
208 && (lexic2->ret_val != NULL && lexic2->ret_val != FAKE_CELL))
209 {
210 retc = lexic2->ret_val;
211 ref_cell (retc);
212 }
213
214 if (nasl_trace_enabled ())
215 nasl_trace (lexic, "NASL> Return %s: %s\n", f->func_name,
216 dump_cell_val (retc));
217 if (!nasl_is_leaf (retc))
218 {
219 nasl_perror (lexic,
220 "nasl_func_call: return value from %s is not atomic!\n",
221 f->func_name);
222 nasl_dump_tree (retc);
223 }
224
225 free_lex_ctxt (lexic2);
226 lexic2 = NULL;
227 return retc;
228
229error:
230 g_free (trace_buf);
231 free_lex_ctxt (lexic2);
232 return NULL;
233}
FILE * nasl_trace_fp
Definition exec.c:357
int nasl_trace_enabled(void)
Checks if the nasl_trace_fp is set.
Definition nasl_debug.c:155
void nasl_set_function_name(const char *funname)
Definition nasl_debug.c:67
void nasl_set_filename(const char *filename)
Definition nasl_debug.c:82
void nasl_trace(lex_ctxt *lexic, char *msg,...)
Prints debug message in printf fashion to nasl_trace_fp if it exists.
Definition nasl_debug.c:169
const char * nasl_get_function_name()
Definition nasl_debug.c:76
const char * nasl_get_filename(const char *function)
Definition nasl_debug.c:54
#define TRACE_BUF_SZ
nasl_func * func_is_internal(const char *)
Definition nasl_init.c:555
void free_lex_ctxt(lex_ctxt *c)
lex_ctxt * init_empty_lex_ctxt()
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *, const char *, tree_cell *)
Definition nasl_var.c:810
anon_nasl_var * add_numbered_var_to_ctxt(lex_ctxt *, int, tree_cell *)
Definition nasl_var.c:781
char * dump_cell_val(const tree_cell *c)
Definition nasl_tree.c:231
int nasl_is_leaf(const tree_cell *pc)
Definition nasl_tree.c:386
struct script_infos * script_infos

References add_named_var_to_ctxt(), add_numbered_var_to_ctxt(), st_nasl_func::block, cell2atom(), deref_cell(), dump_cell_val(), FAKE_CELL, struct_lex_ctxt::fct_ctxt, free_lex_ctxt(), func_is_internal(), st_nasl_func::func_name, init_empty_lex_ctxt(), TC::link, nasl_dump_tree(), nasl_exec(), nasl_get_filename(), nasl_get_function_name(), nasl_is_leaf(), nasl_perror(), nasl_set_filename(), nasl_set_function_name(), nasl_trace(), nasl_trace_enabled(), nasl_trace_fp, struct_lex_ctxt::oid, struct_lex_ctxt::recv_timeout, ref_cell(), struct_lex_ctxt::ret_val, struct_lex_ctxt::script_infos, TC::str_val, TRACE_BUF_SZ, struct_lex_ctxt::up_ctxt, and TC::x.

Referenced by exec_nasl_script(), and nasl_exec().

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

◆ nasl_incr_variable()

tree_cell * nasl_incr_variable ( lex_ctxt * lexic,
tree_cell * tc,
int pre,
int val )

Definition at line 919 of file nasl_var.c.

920 {
921 anon_nasl_var *v;
922 int old_val = 0, new_val;
923 tree_cell *retc;
924
925 if (tc->type != REF_VAR)
926 {
928 lexic, "nasl_incr_variable: argument (type=%d) is not REF_VAR %s\n",
929 tc->type, get_line_nb (tc));
930 return NULL;
931 }
932
933 v = tc->x.ref_val;
934
935 switch (v->var_type)
936 {
937 case VAR2_INT:
938 old_val = v->v.v_int;
939 break;
940 case VAR2_STRING:
941 case VAR2_DATA:
942 old_val =
943 v->v.v_str.s_val == NULL ? 0 : atoi ((char *) v->v.v_str.s_val);
944 break;
945 case VAR2_UNDEF:
946 old_val = 0;
947 break;
948
949 default:
950 nasl_perror (lexic,
951 "nasl_incr_variable: variable %s has bad type %d %s\n",
952 /*get_var_name(v) */ "", get_line_nb (tc));
953 return NULL;
954 }
955 new_val = old_val + val;
956
957 clear_anon_var (v);
958 v->var_type = VAR2_INT;
959 v->v.v_int = new_val;
960
962 retc->x.i_val = pre ? new_val : old_val;
963
964 return retc;
965 }
@ REF_VAR
Definition nasl_tree.h:88
static void clear_anon_var(anon_nasl_var *v)
Definition nasl_var.c:403
long int v_int
Definition nasl_var.h:48

References alloc_typed_cell(), clear_anon_var(), CONST_INT, get_line_nb(), TC::i_val, nasl_perror(), TC::ref_val, REF_VAR, st_nasl_string::s_val, TC::type, st_a_nasl_var::v, st_a_nasl_var::v_int, st_a_nasl_var::v_str, val, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, st_a_nasl_var::var_type, and TC::x.

Referenced by nasl_exec().

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

◆ nasl_read_var_ref()

tree_cell * nasl_read_var_ref ( lex_ctxt * lexic,
tree_cell * tc )

Definition at line 832 of file nasl_var.c.

833 {
834 tree_cell *ret;
835 anon_nasl_var *v;
836
837 if (tc == NULL || tc == FAKE_CELL)
838 {
839 nasl_perror (lexic,
840 "nasl_read_var_ref: cannot read NULL or FAKE cell\n");
841 return NULL;
842 }
843 if (tc->type != REF_VAR)
844 {
845 nasl_perror (lexic,
846 "nasl_read_var_ref: argument (type=%d) is not REF_VAR %s\n",
847 tc->type, get_line_nb (tc));
848 return NULL;
849 }
850
851 v = tc->x.ref_val;
852 if (v == NULL)
853 return NULL;
854
856 ret->line_nb = tc->line_nb;
857
858 switch (v->var_type)
859 {
860 case VAR2_INT:
861 ret->type = CONST_INT;
862 ret->x.i_val = v->v.v_int;
863 if (nasl_trace_enabled ())
864 nasl_trace (lexic, "NASL> %s -> %lu\n", get_var_name (v),
865 ret->x.i_val);
866 return ret;
867
868 case VAR2_STRING:
869 ret->type = CONST_STR;
870 /* Fix bad string length */
871 if (v->v.v_str.s_siz <= 0 && v->v.v_str.s_val[0] != '\0')
872 {
873 v->v.v_str.s_siz = strlen ((char *) v->v.v_str.s_val);
874 nasl_perror (lexic, "nasl_read_var_ref: Bad string length fixed\n");
875 }
876 /* fallthrough */
877 case VAR2_DATA:
879 if (v->v.v_str.s_val == NULL)
880 {
881 ret->x.str_val = NULL;
882 ret->size = 0;
883 }
884 else
885 {
886 ret->x.str_val = g_malloc0 (v->v.v_str.s_siz + 1);
887 memcpy (ret->x.str_val, v->v.v_str.s_val, v->v.v_str.s_siz);
888 ret->size = v->v.v_str.s_siz;
889 }
890 if (nasl_trace_enabled ())
891 nasl_trace (lexic, "NASL> %s -> \"%s\"\n", get_var_name (v),
892 ret->x.str_val);
893 return ret;
894
895 case VAR2_ARRAY:
896 ret->type = REF_ARRAY;
897 ret->x.ref_val = &v->v.v_arr;
898 return ret;
899
900 case VAR2_UNDEF:
901 if (nasl_trace_enabled ())
902 nasl_trace (lexic, "NASL> %s -> undef\n", get_var_name (v),
903 v->var_type);
904 break;
905
906 default:
907 nasl_perror (lexic, "nasl_read_var_ref: unhandled variable type %d\n",
908 v->var_type);
909 if (nasl_trace_enabled ())
910 nasl_trace (lexic, "NASL> %s -> ???? (Var type %d)\n",
911 get_var_name (v), v->var_type);
912 break;
913 }
914 deref_cell (ret);
915 return NULL;
916 }
@ NODE_EMPTY
Definition nasl_tree.h:13
static const char * get_var_name(anon_nasl_var *v)
Definition nasl_var.c:196

References alloc_typed_cell(), CONST_DATA, CONST_INT, CONST_STR, deref_cell(), FAKE_CELL, get_line_nb(), get_var_name(), TC::i_val, TC::line_nb, nasl_perror(), nasl_trace(), nasl_trace_enabled(), NODE_EMPTY, REF_ARRAY, TC::ref_val, REF_VAR, st_nasl_string::s_siz, st_nasl_string::s_val, TC::size, TC::str_val, TC::type, st_a_nasl_var::v, st_a_nasl_var::v_arr, st_a_nasl_var::v_int, st_a_nasl_var::v_str, VAR2_ARRAY, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, st_a_nasl_var::var_type, and TC::x.

Referenced by nasl_exec().

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

◆ nasl_return()

tree_cell * nasl_return ( lex_ctxt * ctxt,
tree_cell * retv )

Definition at line 236 of file nasl_func.c.

237{
238 tree_cell *c;
239
240 retv = cell2atom (ctxt, retv);
241 if (retv == NULL)
242 retv = FAKE_CELL;
243
244 if (retv != FAKE_CELL && retv->type == REF_ARRAY)
245 /* We have to "copy" it as the referenced array will be freed */
246 {
247 c = copy_ref_array (retv);
248 deref_cell (retv);
249 retv = c;
250 }
251
252 while (ctxt != NULL)
253 {
254 ctxt->ret_val = retv;
255 ref_cell (retv);
256 if (ctxt->fct_ctxt)
257 break;
258 ctxt = ctxt->up_ctxt;
259 }
260 /* Bug? Do not return NULL, as we may test it to break the control flow */
261 deref_cell (retv);
262 return FAKE_CELL;
263}
tree_cell * copy_ref_array(const tree_cell *c1)
Definition nasl_var.c:534

References cell2atom(), copy_ref_array(), deref_cell(), FAKE_CELL, struct_lex_ctxt::fct_ctxt, REF_ARRAY, ref_cell(), struct_lex_ctxt::ret_val, TC::type, and struct_lex_ctxt::up_ctxt.

Referenced by nasl_exec().

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