OpenVAS Scanner 23.40.3
nasl_var.c File Reference
#include "nasl_var.h"
#include "nasl_debug.h"
#include "nasl_lex_ctxt.h"
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for nasl_var.c:

Go to the source code of this file.

Functions

static void copy_array (nasl_array *, const nasl_array *, int)
int hash_str2 (const char *s, int n)
static int hash_str (const char *s)
anon_nasl_varnasl_get_var_by_num (void *ctxt, nasl_array *a, int num, int create)
named_nasl_varget_var_by_name (nasl_array *a, const char *s)
static named_nasl_varget_var_ref_by_name (lex_ctxt *ctxt, const char *name, int climb)
 This function climbs up in the context list.
static anon_nasl_varget_var_ref_by_num (lex_ctxt *ctxt, int num)
tree_cellvar2cell (anon_nasl_var *v)
tree_cellget_variable_by_name (lex_ctxt *ctxt, const char *name)
static const char * get_var_name (anon_nasl_var *v)
tree_cellget_array_elem (lex_ctxt *ctxt, const char *name, tree_cell *idx)
static void free_var_chain (named_nasl_var *)
static void free_anon_var (anon_nasl_var *)
void free_array (nasl_array *a)
static void clear_anon_var (anon_nasl_var *v)
static void copy_anon_var (anon_nasl_var *v1, const anon_nasl_var *v2)
static anon_nasl_vardup_anon_var (const anon_nasl_var *v)
static named_nasl_vardup_named_var (const named_nasl_var *v)
tree_cellcopy_ref_array (const tree_cell *c1)
static tree_cellaffect_to_anon_var (anon_nasl_var *v1, tree_cell *rval)
tree_cellnasl_affect (tree_cell *lval, tree_cell *rval)
static named_nasl_varcreate_named_var (const char *name, tree_cell *val)
static anon_nasl_varcreate_anon_var (tree_cell *val)
tree_celldecl_local_variables (lex_ctxt *lexic, tree_cell *vars)
tree_celldecl_global_variables (lex_ctxt *lexic, tree_cell *vars)
anon_nasl_varadd_numbered_var_to_ctxt (lex_ctxt *lexic, int num, tree_cell *val)
named_nasl_varadd_named_var_to_ctxt (lex_ctxt *lexic, const char *name, tree_cell *val)
tree_cellnasl_read_var_ref (lex_ctxt *lexic, tree_cell *tc)
tree_cellnasl_incr_variable (lex_ctxt *lexic, tree_cell *tc, int pre, int val)
static long int var2int (anon_nasl_var *v, int defval)
char * array2str (const nasl_array *a)
const char * var2str (anon_nasl_var *v)
long int get_int_var_by_num (lex_ctxt *lexic, int num, int defval)
long int get_int_var_by_name (lex_ctxt *lexic, const char *name, int defval)
char * get_str_var_by_num (lex_ctxt *lexic, int num)
char * get_str_var_by_name (lex_ctxt *lexic, const char *name)
static long int get_var_size (const anon_nasl_var *v)
long int get_var_size_by_name (lex_ctxt *lexic, const char *name)
long int get_var_size_by_num (lex_ctxt *lexic, int num)
int get_var_type_by_num (lex_ctxt *lexic, int num)
 Returns NASL variable/cell type, VAR2_UNDEF if value is NULL.
int get_var_type_by_name (lex_ctxt *lexic, const char *name)
nasl_iterator nasl_array_iterator (void *ctxt, tree_cell *c)
tree_cellnasl_iterate_array (nasl_iterator *it)
int add_var_to_list (nasl_array *a, int i, const anon_nasl_var *v)
int add_var_to_array (nasl_array *a, char *name, const anon_nasl_var *v)
int array_max_index (nasl_array *a)
tree_cellmake_array_from_elems (tree_cell *el)

Variables

FILE * nasl_trace_fp

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:

◆ add_var_to_array()

int add_var_to_array ( nasl_array * a,
char * name,
const anon_nasl_var * v )

Definition at line 1277 of file nasl_var.c.

1278 {
1279 named_nasl_var *v2;
1280 int h = hash_str (name);
1281
1282 if (a->hash_elt == NULL)
1283 {
1284 a->hash_elt = g_malloc0 (VAR_NAME_HASH * sizeof (named_nasl_var *));
1285 }
1286
1287 v2 = g_malloc0 (sizeof (named_nasl_var));
1288 v2->var_name = g_strdup (name);
1289 v2->u.var_type = VAR2_UNDEF;
1290 v2->next_var = a->hash_elt[h];
1291 a->hash_elt[h] = v2;
1292
1293 copy_anon_var (&(v2->u), v);
1294 return 0;
1295 }
static void copy_anon_var(anon_nasl_var *v1, const anon_nasl_var *v2)
Definition nasl_var.c:427
#define VAR_NAME_HASH
Definition nasl_var.h:22
struct st_a_nasl_var u
Definition nasl_var.h:56

References copy_anon_var(), st_nasl_array::hash_elt, hash_str(), name, st_n_nasl_var::next_var, st_n_nasl_var::u, VAR2_UNDEF, st_n_nasl_var::var_name, VAR_NAME_HASH, and st_a_nasl_var::var_type.

Referenced by get_kb_list(), get_tcp_option(), get_tcp_v6_option(), make_array_from_elems(), nasl_localtime(), nasl_make_array(), parse_notus(), and parse_skiron().

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

◆ add_var_to_list()

int add_var_to_list ( nasl_array * a,
int i,
const anon_nasl_var * v )

Definition at line 1245 of file nasl_var.c.

1246 {
1247 anon_nasl_var *v2 = NULL;
1248
1249 if (i < 0)
1250 {
1251 nasl_perror (
1252 NULL, "add_var_to_list: negative index are not (yet) supported\n");
1253 return -1;
1254 }
1255
1256 if (i >= a->max_idx)
1257 {
1258 a->num_elt = g_realloc (a->num_elt, sizeof (anon_nasl_var *) * (i + 1));
1259 bzero (a->num_elt + a->max_idx,
1260 sizeof (anon_nasl_var *) * (i + 1 - a->max_idx));
1261 a->max_idx = i + 1;
1262 }
1263
1264 if (a->num_elt)
1265 {
1266 free_anon_var (a->num_elt[i]);
1267 v2 = dup_anon_var (v); /* May return NULL */
1268 a->num_elt[i] = v2;
1269 }
1270 if (v2 == NULL)
1271 return 0;
1272 else
1273 return 1;
1274 }
static anon_nasl_var * dup_anon_var(const anon_nasl_var *v)
Definition nasl_var.c:466

References dup_anon_var(), free_anon_var(), st_nasl_array::max_idx, nasl_perror(), and st_nasl_array::num_elt.

Referenced by array_from_snmp_error(), array_from_snmp_result(), crypt_data(), get_hostnames(), make_array_from_elems(), nasl_bf_cbc(), nasl_eregmatch(), nasl_get_sock_info(), nasl_keys(), nasl_make_array(), nasl_make_list(), nasl_split(), parse_notus(), parse_skiron(), and resolve_hostname_to_multiple_ips().

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

◆ affect_to_anon_var()

tree_cell * affect_to_anon_var ( anon_nasl_var * v1,
tree_cell * rval )
static

Definition at line 551 of file nasl_var.c.

552 {
553 anon_nasl_var *v2 = NULL, v0;
554 nasl_array *a = NULL;
555 int t2;
556 void *p;
557
558 if (v1 == NULL || v1 == FAKE_CELL)
559 return NULL;
560
561 if (rval == NULL || rval == FAKE_CELL)
562 {
563 clear_anon_var (v1);
564 if (nasl_trace_enabled ())
565 nasl_trace (NULL, "NASL> %s <- undef\n", get_var_name (v1));
566 return NULL;
567 }
568
569 switch (rval->type)
570 {
571 case CONST_INT:
572 t2 = VAR2_INT;
573 break;
574 case CONST_STR:
575 t2 = VAR2_STRING;
576 break;
577 case CONST_DATA:
578 t2 = VAR2_DATA;
579 break;
580
581 case REF_VAR:
582 v2 = rval->x.ref_val;
583 if (v2 == NULL)
584 {
585 t2 = 0;
586 a = NULL;
587 break;
588 }
589
590 if (v2 == v1)
591 return FAKE_CELL;
592
593 t2 = v2->var_type;
594 if (t2 == VAR2_ARRAY)
595 a = &v2->v.v_arr; /* ? */
596 break;
597
598 case REF_ARRAY:
599 case DYN_ARRAY:
600 a = rval->x.ref_val;
601 t2 = VAR2_ARRAY;
602 if (v1->var_type == VAR2_ARRAY && &v1->v.v_arr == a)
603 return FAKE_CELL;
604 break;
605
606 default:
607 nasl_perror (NULL, "Cannot affect rvalue 0x%x to variable\n",
608 rval->type);
609 return NULL;
610 }
611
612 /*
613 * Bug #146: when executing
614 * x = 'abc'; x = x; or x = make_list(...); x = x[0];
615 * the rvalue will be freed before it is copied to the lvalue
616 */
617 v0 = *v1;
618
619 /* Bug #146: this fake clear is necessary if we copy an array */
620 memset (v1, 0, sizeof (*v1));
621 /* Bug #146: no risk with the type, we already copied it */
622 v1->var_type = t2;
623
624 if (rval->type != REF_VAR && rval->type != REF_ARRAY
625 && rval->type != DYN_ARRAY)
626 switch (t2)
627 {
628 case VAR2_INT:
629 v1->v.v_int = rval->x.i_val;
630 break;
631 case VAR2_STRING:
632 case VAR2_DATA:
633 if (rval->x.str_val == NULL)
634 {
635 v1->v.v_str.s_val = NULL;
636 v1->v.v_str.s_siz = 0;
637 }
638 else
639 {
640 p = g_malloc0 (rval->size + 1);
641 memcpy (p, rval->x.str_val, rval->size);
642 v1->v.v_str.s_siz = rval->size;
643 v1->v.v_str.s_val = p;
644 }
645 break;
646 }
647 else /* REF_xxx */
648 switch (t2)
649 {
650 case VAR2_INT:
651 v1->v.v_int = v2->v.v_int;
652 break;
653 case VAR2_STRING:
654 case VAR2_DATA:
655 if (v2->v.v_str.s_val == NULL)
656 {
657 v1->v.v_str.s_val = NULL;
658 v1->v.v_str.s_siz = 0;
659 }
660 else
661 {
662 p = g_malloc0 (v2->v.v_str.s_siz + 1);
663 memcpy (p, v2->v.v_str.s_val, v2->v.v_str.s_siz);
664 v1->v.v_str.s_siz = v2->v.v_str.s_siz;
665 v1->v.v_str.s_val = p;
666 }
667 break;
668 case VAR2_ARRAY:
669 copy_array (&v1->v.v_arr, a, 1);
670 break;
671 }
672
673 if (nasl_trace_fp != NULL)
674 switch (t2)
675 {
676 case VAR2_INT:
677 nasl_trace (NULL, "NASL> %s <- %lu\n", get_var_name (v1), v1->v.v_int);
678 break;
679 case VAR2_STRING:
680 case VAR2_DATA:
681 nasl_trace (NULL, "NASL> %s <- \"%s\"\n", get_var_name (v1),
682 v1->v.v_str.s_val);
683 break;
684 case VAR2_ARRAY:
685 nasl_trace (NULL, "NASL> %s <- (VAR2_ARRAY)\n", get_var_name (v1));
686 break;
687 default:
688 nasl_trace (NULL, "NASL> %s <- (Type 0x%x)\n", get_var_name (v1), t2);
689 break;
690 }
691
692 clear_anon_var (&v0);
693 return FAKE_CELL;
694 }
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_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_DATA
Definition nasl_tree.h:82
@ REF_VAR
Definition nasl_tree.h:88
@ 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
#define FAKE_CELL
Definition nasl_tree.h:110
static void copy_array(nasl_array *, const nasl_array *, int)
Definition nasl_var.c:493
static void clear_anon_var(anon_nasl_var *v)
Definition nasl_var.c:403
static const char * get_var_name(anon_nasl_var *v)
Definition nasl_var.c:196
@ 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
union TC::@332262321161220155002104006201360276211317150140 x
char * str_val
Definition nasl_tree.h:103
void * ref_val
Definition nasl_tree.h:105
short type
Definition nasl_tree.h:95
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
long int v_int
Definition nasl_var.h:48
unsigned char * s_val
Definition nasl_var.h:26
long int s_siz
Definition nasl_var.h:27

References clear_anon_var(), CONST_DATA, CONST_INT, CONST_STR, copy_array(), DYN_ARRAY, FAKE_CELL, get_var_name(), TC::i_val, nasl_perror(), nasl_trace(), nasl_trace_enabled(), nasl_trace_fp, 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, st_a_nasl_var::var_type, and TC::x.

Referenced by create_anon_var(), create_named_var(), and nasl_affect().

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

◆ array2str()

char * array2str ( const nasl_array * a)

Definition at line 990 of file nasl_var.c.

991 {
992 GString *str;
993 int i, n1 = 0;
994 anon_nasl_var *u;
996
997 if (a == NULL)
998 return NULL;
999
1000 str = g_string_new ("[ ");
1001 if (a->num_elt != NULL)
1002 for (i = 0; i < a->max_idx; i++)
1003 if ((u = a->num_elt[i]) != NULL && u->var_type != VAR2_UNDEF)
1004 {
1005 if (n1 > 0)
1006 g_string_append (str, ", ");
1007 n1++;
1008 switch (u->var_type)
1009 {
1010 case VAR2_INT:
1011 g_string_append_printf (str, "%d: %ld", i, u->v.v_int);
1012 break;
1013 case VAR2_STRING:
1014 case VAR2_DATA:
1015 if (u->v.v_str.s_siz < 64)
1016 g_string_append_printf (str, "%d: '%s'", i, u->v.v_str.s_val);
1017 else
1018 g_string_append_printf (str, "%d: '%s'...", i,
1019 u->v.v_str.s_val);
1020 break;
1021 default:
1022 g_string_append_printf (str, "%d: ????", i);
1023 break;
1024 }
1025 }
1026
1027 if (a->hash_elt != NULL)
1028 for (i = 0; i < VAR_NAME_HASH; i++)
1029 for (v = a->hash_elt[i]; v != NULL; v = v->next_var)
1030 if (v->u.var_type != VAR2_UNDEF)
1031 {
1032 u = &v->u;
1033 if (n1 > 0)
1034 g_string_append (str, ", ");
1035 n1++;
1036 switch (u->var_type)
1037 {
1038 case VAR2_INT:
1039 g_string_append_printf (str, "%s: %ld", v->var_name,
1040 u->v.v_int);
1041 break;
1042 case VAR2_STRING:
1043 case VAR2_DATA:
1044 if (u->v.v_str.s_siz < 64)
1045 g_string_append_printf (str, "%s: '%s'", v->var_name,
1046 u->v.v_str.s_val);
1047 else
1048 g_string_append_printf (str, "%s: '%s'...", v->var_name,
1049 u->v.v_str.s_val);
1050 break;
1051 default:
1052 g_string_append_printf (str, "%s: ????", v->var_name);
1053 break;
1054 }
1055 }
1056
1057 g_string_append (str, " ]");
1058 return g_string_free (str, FALSE);
1059 }

References st_nasl_array::hash_elt, st_nasl_array::max_idx, st_n_nasl_var::next_var, st_nasl_array::num_elt, st_nasl_string::s_siz, st_nasl_string::s_val, st_n_nasl_var::u, st_a_nasl_var::v, st_a_nasl_var::v_int, st_a_nasl_var::v_str, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, st_n_nasl_var::var_name, VAR_NAME_HASH, and st_a_nasl_var::var_type.

Referenced by cell2str(), and var2str().

Here is the caller graph for this function:

◆ array_max_index()

int array_max_index ( nasl_array * a)

The name is not great: this function does not returns the index of the last element, but the index of the next free slot

Definition at line 1302 of file nasl_var.c.

1303 {
1304 int i;
1305
1306 for (i = a->max_idx - 1; i >= 0; i--)
1307 if (a->num_elt[i] != NULL && a->num_elt[i]->var_type != VAR2_UNDEF)
1308 {
1309 /* Fixing max_index will realloc() at next store.
1310 * I am not sure it is a good idea
1311 * Wait and see */
1312 a->max_idx = i + 1;
1313 return i + 1;
1314 }
1315 return 0;
1316 }

References st_nasl_array::max_idx, st_nasl_array::num_elt, VAR2_UNDEF, and st_a_nasl_var::var_type.

Referenced by nasl_max_index(), nasl_rawstring(), nasl_strcat(), and nasl_string().

Here is the caller graph for this function:

◆ clear_anon_var()

void clear_anon_var ( anon_nasl_var * v)
static

Definition at line 403 of file nasl_var.c.

404 {
405 if (v == NULL)
406 return;
407
408 switch (v->var_type)
409 {
410 case VAR2_INT:
411 v->v.v_int = 0;
412 break;
413 case VAR2_STRING:
414 case VAR2_DATA:
415 g_free (v->v.v_str.s_val);
416 v->v.v_str.s_val = NULL;
417 v->v.v_str.s_siz = 0;
418 break;
419 case VAR2_ARRAY:
420 free_array (&v->v.v_arr);
421 break;
422 }
423 v->var_type = VAR2_UNDEF;
424 }
void free_array(nasl_array *a)
Definition nasl_var.c:339

References free_array(), st_nasl_string::s_siz, st_nasl_string::s_val, 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, and st_a_nasl_var::var_type.

Referenced by affect_to_anon_var(), copy_anon_var(), and nasl_incr_variable().

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

◆ copy_anon_var()

void copy_anon_var ( anon_nasl_var * v1,
const anon_nasl_var * v2 )
static

Definition at line 427 of file nasl_var.c.

428 {
429 /* TBD: free variable if necessary? */
430 v1->var_type = v2->var_type;
431 switch (v2->var_type)
432 {
433 case VAR2_STRING:
434 case VAR2_DATA:
435 if (v2->v.v_str.s_val != NULL)
436 {
437 v1->v.v_str.s_val = g_malloc0 (v2->v.v_str.s_siz + 1);
438 memcpy (v1->v.v_str.s_val, v2->v.v_str.s_val, v2->v.v_str.s_siz);
439 v1->v.v_str.s_siz = v2->v.v_str.s_siz;
440 }
441 else
442 {
443 v1->v.v_str.s_val = NULL;
444 v1->v.v_str.s_siz = 0;
445 }
446 break;
447
448 case VAR2_UNDEF:
449 break;
450
451 case VAR2_INT:
452 v1->v.v_int = v2->v.v_int;
453 break;
454
455 case VAR2_ARRAY:
456 copy_array (&v1->v.v_arr, &v2->v.v_arr, 1);
457 break;
458
459 default:
460 nasl_perror (NULL, "copy_anon_var: unhandled type 0x%x\n", v2->var_type);
461 clear_anon_var (v1);
462 }
463 }

References clear_anon_var(), copy_array(), nasl_perror(), st_nasl_string::s_siz, st_nasl_string::s_val, 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, and st_a_nasl_var::var_type.

Referenced by add_var_to_array(), dup_anon_var(), and dup_named_var().

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

◆ copy_array()

void copy_array ( nasl_array * a1,
const nasl_array * a2,
int copy_named )
static

Definition at line 493 of file nasl_var.c.

494 {
495 int i;
496 named_nasl_var *v1, *v2, *v;
497
498 if (a1 == a2)
499 return;
500
501 if (a1 == NULL || a2 == NULL)
502 {
503 nasl_perror (NULL, "Internal inconsistency - null array\n");
504 abort ();
505 }
506
507 free_array (a1);
508
509 if (a2->num_elt != NULL)
510 {
511 a1->max_idx = a2->max_idx;
512 a1->num_elt = g_malloc0 (sizeof (anon_nasl_var *) * a2->max_idx);
513 for (i = 0; i < a2->max_idx; i++)
514 a1->num_elt[i] = dup_anon_var (a2->num_elt[i]);
515 }
516 if (copy_named && a2->hash_elt != NULL)
517 {
518 a1->hash_elt = g_malloc0 (VAR_NAME_HASH * sizeof (named_nasl_var *));
519 for (i = 0; i < VAR_NAME_HASH; i++)
520 {
521 v1 = NULL;
522 for (v2 = a2->hash_elt[i]; v2 != NULL; v2 = v2->next_var)
523 {
524 v = dup_named_var (v2);
525 v->next_var = v1;
526 a1->hash_elt[i] = v;
527 v1 = v;
528 }
529 }
530 }
531 }
static named_nasl_var * dup_named_var(const named_nasl_var *v)
Definition nasl_var.c:479

References dup_anon_var(), dup_named_var(), free_array(), st_nasl_array::hash_elt, st_nasl_array::max_idx, nasl_perror(), st_n_nasl_var::next_var, st_nasl_array::num_elt, and VAR_NAME_HASH.

Referenced by affect_to_anon_var(), copy_anon_var(), copy_ref_array(), get_variable_by_name(), and nasl_array_iterator().

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

◆ copy_ref_array()

tree_cell * copy_ref_array ( const tree_cell * c1)

Definition at line 534 of file nasl_var.c.

535 {
536 tree_cell *c2;
537 nasl_array *a2;
538
539 if (c1 == NULL || c1 == FAKE_CELL || c1->type != REF_ARRAY)
540 return NULL;
541
543 c2->x.ref_val = a2 = g_malloc0 (sizeof (nasl_array));
544 copy_array (a2, c1->x.ref_val, 1);
545 return c2;
546 }
tree_cell * alloc_typed_cell(int typ)
Definition nasl_tree.c:25
struct TC tree_cell

References alloc_typed_cell(), copy_array(), DYN_ARRAY, FAKE_CELL, REF_ARRAY, TC::ref_val, TC::type, and TC::x.

Referenced by nasl_return().

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

◆ create_anon_var()

anon_nasl_var * create_anon_var ( tree_cell * val)
static

Definition at line 740 of file nasl_var.c.

741 {
742 anon_nasl_var *v = g_malloc0 (sizeof (anon_nasl_var));
743 tree_cell *tc;
744
745 if (val == NULL || val == FAKE_CELL)
746 {
747 v->var_type = VAR2_UNDEF;
748 return v;
749 }
750
751 tc = affect_to_anon_var (v, val);
752 /* Here we might test the return value */
753 deref_cell (tc);
754 return v;
755 }
void deref_cell(tree_cell *c)
Definition nasl_tree.c:178
static tree_cell * affect_to_anon_var(anon_nasl_var *v1, tree_cell *rval)
Definition nasl_var.c:551

References affect_to_anon_var(), deref_cell(), FAKE_CELL, val, VAR2_UNDEF, and st_a_nasl_var::var_type.

Referenced by add_numbered_var_to_ctxt().

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

◆ create_named_var()

named_nasl_var * create_named_var ( const char * name,
tree_cell * val )
static

Definition at line 719 of file nasl_var.c.

720 {
721 named_nasl_var *v = g_malloc0 (sizeof (named_nasl_var));
722 tree_cell *tc;
723
724 if (name != NULL)
725 v->var_name = g_strdup (name);
726
727 if (val == NULL || val == FAKE_CELL)
728 {
729 v->u.var_type = VAR2_UNDEF;
730 return v;
731 }
732
733 tc = affect_to_anon_var (&v->u, val);
734 /* Here we might test the return value */
735 deref_cell (tc);
736 return v;
737 }

References affect_to_anon_var(), deref_cell(), FAKE_CELL, name, st_n_nasl_var::u, val, VAR2_UNDEF, st_n_nasl_var::var_name, and st_a_nasl_var::var_type.

Referenced by add_named_var_to_ctxt().

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

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:

◆ dup_anon_var()

anon_nasl_var * dup_anon_var ( const anon_nasl_var * v)
static

Definition at line 466 of file nasl_var.c.

467 {
468 anon_nasl_var *v1;
469
470 if (v == NULL)
471 return NULL;
472
473 v1 = g_malloc0 (sizeof (anon_nasl_var));
474 copy_anon_var (v1, v);
475 return v1;
476 }

References copy_anon_var().

Referenced by add_var_to_list(), and copy_array().

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

◆ dup_named_var()

named_nasl_var * dup_named_var ( const named_nasl_var * v)
static

Definition at line 479 of file nasl_var.c.

480 {
481 named_nasl_var *v1;
482
483 if (v == NULL)
484 return NULL;
485
486 v1 = g_malloc0 (sizeof (named_nasl_var));
487 copy_anon_var (&v1->u, &v->u);
488 v1->var_name = g_strdup (v->var_name);
489 return v1;
490 }

References copy_anon_var(), st_n_nasl_var::u, and st_n_nasl_var::var_name.

Referenced by copy_array().

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

◆ free_anon_var()

void free_anon_var ( anon_nasl_var * v)
static

Definition at line 384 of file nasl_var.c.

385 {
386 if (v == NULL)
387 return;
388 switch (v->var_type)
389 {
390 case VAR2_STRING:
391 case VAR2_DATA:
392 g_free (v->v.v_str.s_val);
393 break;
394 case VAR2_ARRAY:
395 free_array (&v->v.v_arr);
396 break;
397 }
398 g_free (v->string_form);
399 g_free (v);
400 }
char * string_form
Definition nasl_var.h:51

References free_array(), st_nasl_string::s_val, st_a_nasl_var::string_form, st_a_nasl_var::v, st_a_nasl_var::v_arr, st_a_nasl_var::v_str, VAR2_ARRAY, VAR2_DATA, VAR2_STRING, and st_a_nasl_var::var_type.

Referenced by add_numbered_var_to_ctxt(), add_var_to_list(), and free_array().

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

◆ free_array()

void free_array ( nasl_array * a)

Note: the function does not free the nasl_array structure. Do it if necessary

Definition at line 339 of file nasl_var.c.

340 {
341 int i;
342
343 if (a == NULL)
344 return;
345 if (a->num_elt != NULL)
346 {
347 for (i = 0; i < a->max_idx; i++)
348 free_anon_var (a->num_elt[i]);
349 g_free (a->num_elt);
350 a->num_elt = NULL;
351 }
352 a->max_idx = 0;
353 if (a->hash_elt != NULL)
354 {
355 for (i = 0; i < VAR_NAME_HASH; i++)
356 free_var_chain (a->hash_elt[i]);
357 g_free (a->hash_elt);
358 a->hash_elt = NULL;
359 }
360 }
static void free_var_chain(named_nasl_var *)
Definition nasl_var.c:363

References free_anon_var(), free_var_chain(), st_nasl_array::hash_elt, st_nasl_array::max_idx, st_nasl_array::num_elt, and VAR_NAME_HASH.

Referenced by clear_anon_var(), copy_array(), free_anon_var(), free_lex_ctxt(), free_tree(), free_var_chain(), and nasl_exec().

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

◆ free_var_chain()

void free_var_chain ( named_nasl_var * v)
static

Definition at line 363 of file nasl_var.c.

364 {
365 if (v == NULL)
366 return;
368 g_free (v->var_name);
369 switch (v->u.var_type)
370 {
371 case VAR2_STRING:
372 case VAR2_DATA:
373 g_free (v->u.v.v_str.s_val);
374 break;
375 case VAR2_ARRAY:
376 free_array (&v->u.v.v_arr);
377 break;
378 }
379 g_free (v->u.string_form);
380 g_free (v);
381 }

References free_array(), free_var_chain(), st_n_nasl_var::next_var, st_nasl_string::s_val, st_a_nasl_var::string_form, st_n_nasl_var::u, st_a_nasl_var::v, st_a_nasl_var::v_arr, st_a_nasl_var::v_str, VAR2_ARRAY, VAR2_DATA, VAR2_STRING, st_n_nasl_var::var_name, and st_a_nasl_var::var_type.

Referenced by free_array(), and free_var_chain().

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
short line_nb
Definition nasl_tree.h:96

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_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_by_name()

named_nasl_var * get_var_by_name ( nasl_array * a,
const char * s )

Definition at line 75 of file nasl_var.c.

76{
77 int h = hash_str (s);
79
80 if (a->hash_elt == NULL)
81 a->hash_elt = g_malloc0 (VAR_NAME_HASH * sizeof (named_nasl_var *));
82
83 for (v = a->hash_elt[h]; v != NULL; v = v->next_var)
84 if (v->var_name != NULL && strcmp (s, v->var_name) == 0)
85 return v;
86
87 v = g_malloc0 (sizeof (named_nasl_var));
88 v->var_name = g_strdup (s);
90 v->next_var = a->hash_elt[h];
91
92 a->hash_elt[h] = v;
93 return v;
94}

References st_nasl_array::hash_elt, hash_str(), st_n_nasl_var::next_var, st_n_nasl_var::u, VAR2_UNDEF, st_n_nasl_var::var_name, VAR_NAME_HASH, and st_a_nasl_var::var_type.

Referenced by get_array_elem(), get_notus_result_message(), and security_notus().

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

◆ get_var_name()

const char * get_var_name ( anon_nasl_var * v)
static

Definition at line 196 of file nasl_var.c.

197 {
198 static char str[16];
199#ifdef ALL_VARIABLES_NAMED
200 if (v->av_name != NULL)
201 return v->av_name;
202#endif
203 snprintf (str, sizeof (str), "[%p]", (void *) v);
204 return str;
205 }

Referenced by affect_to_anon_var(), and nasl_read_var_ref().

Here is the caller graph for this function:

◆ get_var_ref_by_name()

named_nasl_var * get_var_ref_by_name ( lex_ctxt * ctxt,
const char * name,
int climb )
static

This function climbs up in the context list.

Definition at line 100 of file nasl_var.c.

101{
103 int h = hash_str (name);
104 lex_ctxt *c;
105
106 if (!ctxt)
107 return NULL;
108 if (climb != 0)
109 {
110 for (c = ctxt; c != NULL; c = c->up_ctxt)
111 if (c->ctx_vars.hash_elt != NULL)
112 for (v = c->ctx_vars.hash_elt[h]; v != NULL; v = v->next_var)
113 if (v->var_name != NULL && strcmp (name, v->var_name) == 0)
114 return v;
115 }
116 else
117 {
118 if (ctxt->ctx_vars.hash_elt != NULL)
119 for (v = ctxt->ctx_vars.hash_elt[h]; v != NULL; v = v->next_var)
120 if (v->var_name != NULL && strcmp (name, v->var_name) == 0)
121 return v;
122 }
123
124 if (ctxt->ctx_vars.hash_elt == NULL)
125 ctxt->ctx_vars.hash_elt =
126 g_malloc0 (sizeof (named_nasl_var *) * VAR_NAME_HASH);
127
128 v = g_malloc0 (sizeof (named_nasl_var));
129 v->var_name = g_strdup (name);
130 v->u.var_type = VAR2_UNDEF;
131 v->next_var = ctxt->ctx_vars.hash_elt[h];
132 ctxt->ctx_vars.hash_elt[h] = v;
133
134 return v;
135}

References struct_lex_ctxt::ctx_vars, st_nasl_array::hash_elt, hash_str(), name, st_n_nasl_var::next_var, st_n_nasl_var::u, struct_lex_ctxt::up_ctxt, VAR2_UNDEF, st_n_nasl_var::var_name, VAR_NAME_HASH, and st_a_nasl_var::var_type.

Referenced by get_array_elem(), get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), get_var_type_by_name(), and get_variable_by_name().

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

◆ get_var_ref_by_num()

anon_nasl_var * get_var_ref_by_num ( lex_ctxt * ctxt,
int num )
static

Definition at line 138 of file nasl_var.c.

139{
140 anon_nasl_var *v;
141
142 if (num < 0) /* safer */
143 {
144 nasl_perror (ctxt, "Negative index %d is invalid for array\n", num);
145 return NULL;
146 }
147
148 if (ctxt->ctx_vars.max_idx <= num)
149 {
150 ctxt->ctx_vars.num_elt = g_realloc (ctxt->ctx_vars.num_elt,
151 sizeof (anon_nasl_var *) * (num + 1));
152 bzero (ctxt->ctx_vars.num_elt + ctxt->ctx_vars.max_idx,
153 sizeof (anon_nasl_var *) * (num + 1 - ctxt->ctx_vars.max_idx));
154 ctxt->ctx_vars.max_idx = num + 1;
155 }
156
157 v = ctxt->ctx_vars.num_elt[num];
158 if (v != NULL)
159 return v;
160
161 v = g_malloc0 (sizeof (anon_nasl_var));
162 v->var_type = VAR2_UNDEF;
163 ctxt->ctx_vars.num_elt[num] = v;
164 return v;
165}

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

Referenced by get_int_var_by_num(), get_str_var_by_num(), get_var_size_by_num(), and get_var_type_by_num().

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

◆ get_var_size()

long int get_var_size ( const anon_nasl_var * v)
static

Definition at line 1124 of file nasl_var.c.

1125 {
1126 if (v == NULL)
1127 return 0;
1128 switch (v->var_type)
1129 {
1130 case VAR2_DATA:
1131 case VAR2_STRING:
1132 return v->v.v_str.s_siz;
1133 }
1134 return 0;
1135 }

References st_nasl_string::s_siz, st_a_nasl_var::v, st_a_nasl_var::v_str, VAR2_DATA, VAR2_STRING, and st_a_nasl_var::var_type.

Referenced by get_var_size_by_name(), and get_var_size_by_num().

Here is the caller graph for this function:

◆ 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*/}

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:

◆ hash_str()

int hash_str ( const char * s)
static

Definition at line 37 of file nasl_var.c.

38{
39 return hash_str2 (s, VAR_NAME_HASH);
40}
int hash_str2(const char *s, int n)
Definition nasl_var.c:23

References hash_str2(), and VAR_NAME_HASH.

Referenced by add_named_var_to_ctxt(), add_var_to_array(), get_var_by_name(), and get_var_ref_by_name().

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

◆ hash_str2()

int hash_str2 ( const char * s,
int n )
Todo
Consider using GLibs string hash function.

Definition at line 23 of file nasl_var.c.

24{
25 unsigned long h = 0;
26 const char *p;
27
28 if (s == NULL)
29 return 0;
30
31 for (p = s; *p != '\0'; p++)
32 h = (h << 3) + (unsigned char) *p;
33 return h % n;
34}

Referenced by hash_str().

Here is the caller graph for this function:

◆ make_array_from_elems()

tree_cell * make_array_from_elems ( tree_cell * el)

make_array_from_list is used by the parser only The list of elements is freed after use

Definition at line 1323 of file nasl_var.c.

1324 {
1325 int n;
1326 tree_cell *c, *c2;
1327 nasl_array *a;
1328 anon_nasl_var *v;
1329
1330 v = g_malloc0 (sizeof (anon_nasl_var));
1331 a = g_malloc0 (sizeof (nasl_array));
1332 /* Either the elements are all "named", or they are "numbered". No mix! */
1333 if (el->x.str_val == NULL) /* numbered */
1334 {
1335 for (n = 0, c = el; c != NULL; c = c->link[1])
1336 n++;
1337 a->max_idx = n;
1338 a->num_elt = g_malloc0 (sizeof (anon_nasl_var *) * n);
1339 a->hash_elt = NULL;
1340 }
1341 else
1342 {
1343 a->num_elt = NULL;
1344 a->hash_elt = g_malloc0 (VAR_NAME_HASH * sizeof (named_nasl_var *));
1345 }
1346
1347 for (n = 0, c = el; c != NULL; c = c->link[1])
1348 {
1349 c2 = c->link[0];
1350 if (c2 != NULL && c2 != FAKE_CELL)
1351 {
1352 switch (c2->type)
1353 {
1354 case CONST_INT:
1355 v->var_type = VAR2_INT;
1356 v->v.v_int = c2->x.i_val;
1357 break;
1358 case CONST_STR:
1359 case CONST_DATA:
1361 if (c2->x.str_val == NULL)
1362 {
1363 v->v.v_str.s_val = NULL;
1364 v->v.v_str.s_siz = 0;
1365 }
1366 else
1367 {
1368 v->v.v_str.s_siz = c2->size;
1369 v->v.v_str.s_val = (unsigned char *) c2->x.str_val;
1370 }
1371 break;
1372 default:
1373 nasl_perror (NULL,
1374 "make_array_from_list: unhandled cell type %s at "
1375 "position %d\n",
1376 nasl_type_name (c2->type), n);
1377 v->var_type = VAR2_UNDEF;
1378 break;
1379 }
1380 }
1381
1382 if (c->x.str_val == NULL)
1383 add_var_to_list (a, n++, v);
1384 else
1385 add_var_to_array (a, c->x.str_val, v);
1386 }
1387
1388 g_free (v);
1390 c->x.ref_val = a;
1391 deref_cell (el);
1392 return c;
1393 }
const char * nasl_type_name(int t)
Definition nasl_tree.c:343
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition nasl_var.c:1277
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition nasl_var.c:1245

References add_var_to_array(), add_var_to_list(), alloc_typed_cell(), CONST_DATA, CONST_INT, CONST_STR, deref_cell(), DYN_ARRAY, FAKE_CELL, st_nasl_array::hash_elt, TC::i_val, TC::link, st_nasl_array::max_idx, nasl_perror(), nasl_type_name(), st_nasl_array::num_elt, TC::ref_val, 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_int, st_a_nasl_var::v_str, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, VAR_NAME_HASH, st_a_nasl_var::var_type, and TC::x.

Referenced by yyparse().

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

◆ nasl_affect()

tree_cell * nasl_affect ( tree_cell * lval,
tree_cell * rval )

Definition at line 697 of file nasl_var.c.

698 {
699 anon_nasl_var *v1 = NULL;
700
701 if (lval == NULL)
702 {
703 nasl_perror (NULL, "nasl_effect: invalid lvalue\n");
704 return NULL;
705 }
706
707 if (lval->type != REF_VAR)
708 {
709 nasl_perror (NULL, "nasl_affect: cannot affect to non variable %s\n",
710 nasl_type_name (lval->type));
711 return NULL;
712 }
713
714 v1 = lval->x.ref_val;
715 return affect_to_anon_var (v1, rval);
716 }

References affect_to_anon_var(), nasl_perror(), nasl_type_name(), TC::ref_val, REF_VAR, TC::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_array_iterator()

nasl_iterator nasl_array_iterator ( void * ctxt,
tree_cell * c )

Definition at line 1169 of file nasl_var.c.

1170 {
1171 nasl_iterator it;
1172 anon_nasl_var *v;
1173
1174 it.a = NULL;
1175 it.v = NULL;
1176 it.i1 = 0;
1177 it.iH = 0;
1178
1179 if (c == NULL || c == FAKE_CELL)
1180 return it;
1181
1182 if (c->type == REF_VAR)
1183 {
1184 v = c->x.ref_val;
1185 if (v == NULL || v->var_type != VAR2_ARRAY)
1186 return it;
1187 it.a = g_malloc0 (sizeof (nasl_array));
1188 copy_array (it.a, &v->v.v_arr, 1);
1189 }
1190 else if (c->type == REF_ARRAY || c->type == DYN_ARRAY)
1191 {
1192 it.a = g_malloc0 (sizeof (nasl_array));
1193 copy_array (it.a, c->x.ref_val, 1);
1194 }
1195 else
1196 {
1197 nasl_perror (ctxt, "nasl_array_iterator: unhandled type %d (0x%x)\n",
1198 c->type, c->type);
1199 }
1200
1201 return it;
1202 }
named_nasl_var * v
Definition nasl_var.h:70
nasl_array * a
Definition nasl_var.h:67

References nasl_iterator::a, copy_array(), DYN_ARRAY, FAKE_CELL, nasl_iterator::i1, nasl_iterator::iH, nasl_perror(), REF_ARRAY, TC::ref_val, REF_VAR, TC::type, nasl_iterator::v, st_a_nasl_var::v, st_a_nasl_var::v_arr, VAR2_ARRAY, 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_get_var_by_num()

anon_nasl_var * nasl_get_var_by_num ( void * ctxt,
nasl_array * a,
int num,
int create )

Definition at line 43 of file nasl_var.c.

44{
45 anon_nasl_var *v = NULL;
46
47 if (num < 0)
48 {
49 /* TBD: implement a min_index field, just like $[ in Perl */
50 nasl_perror (ctxt, "Negative integer index %d are not supported yet!\n",
51 num);
52 return NULL;
53 }
54
55 if (num < a->max_idx)
56 v = a->num_elt[num];
57 if (v != NULL || !create)
58 return v;
59
60 if (num >= a->max_idx)
61 {
62 a->num_elt = g_realloc (a->num_elt, sizeof (anon_nasl_var *) * (num + 1));
63 bzero (a->num_elt + a->max_idx,
64 sizeof (anon_nasl_var *) * (num + 1 - a->max_idx));
65 a->max_idx = num + 1;
66 }
67 v = g_malloc0 (sizeof (anon_nasl_var));
69
70 a->num_elt[num] = v;
71 return v;
72}

References st_nasl_array::max_idx, nasl_perror(), st_nasl_array::num_elt, VAR2_UNDEF, and st_a_nasl_var::var_type.

Referenced by get_array_elem(), get_notus_result_message(), nasl_keys(), nasl_make_array(), nasl_make_list(), nasl_max_index(), and nasl_typeof().

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 }

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_iterate_array()

tree_cell * nasl_iterate_array ( nasl_iterator * it)

Definition at line 1205 of file nasl_var.c.

1206 {
1207 anon_nasl_var *av;
1208
1209 if (it == NULL || it->a == NULL)
1210 return NULL;
1211
1212 if (it->i1 >= 0)
1213 {
1214 while (it->i1 < it->a->max_idx)
1215 {
1216 av = it->a->num_elt[it->i1++];
1217 if (av != NULL && av->var_type != VAR2_UNDEF)
1218 return var2cell (av);
1219 }
1220 it->i1 = -1;
1221 }
1222
1223 if (it->a->hash_elt == NULL)
1224 return NULL;
1225
1226 if (it->v != NULL)
1227 it->v = it->v->next_var;
1228 do
1229 {
1230 while (it->v == NULL)
1231 if (it->iH >= VAR_NAME_HASH)
1232 return NULL;
1233 else
1234 it->v = it->a->hash_elt[it->iH++];
1235
1236 while (it->v != NULL && it->v->u.var_type == VAR2_UNDEF)
1237 it->v = it->v->next_var;
1238 }
1239 while (it->v == NULL);
1240
1241 return var2cell (&it->v->u);
1242 }

References nasl_iterator::a, st_nasl_array::hash_elt, nasl_iterator::i1, nasl_iterator::iH, st_nasl_array::max_idx, st_n_nasl_var::next_var, st_nasl_array::num_elt, st_n_nasl_var::u, nasl_iterator::v, VAR2_UNDEF, var2cell(), VAR_NAME_HASH, and st_a_nasl_var::var_type.

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

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:

◆ var2cell()

tree_cell * var2cell ( anon_nasl_var * v)

Definition at line 168 of file nasl_var.c.

169{
171 tc->x.ref_val = v; /* No need to free this later! */
172 return tc;
173}

References alloc_typed_cell(), TC::ref_val, REF_VAR, and TC::x.

Referenced by get_array_elem(), get_variable_by_name(), nasl_iterate_array(), and var_cmp().

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

◆ var2int()

long int var2int ( anon_nasl_var * v,
int defval )
static

Definition at line 968 of file nasl_var.c.

969 {
970 if (v == NULL)
971 return defval;
972
973 switch (v->var_type)
974 {
975 case VAR2_INT:
976 return v->v.v_int;
977
978 case VAR2_STRING:
979 case VAR2_DATA:
980 return atol ((char *) v->v.v_str.s_val);
981
982 case VAR2_UNDEF:
983 case VAR2_ARRAY:
984 default:
985 return defval;
986 }
987 /*NOTREACHED*/}

References st_nasl_string::s_val, st_a_nasl_var::v, st_a_nasl_var::v_int, st_a_nasl_var::v_str, VAR2_ARRAY, VAR2_DATA, VAR2_INT, VAR2_STRING, VAR2_UNDEF, and st_a_nasl_var::var_type.

Referenced by get_int_var_by_name(), and get_int_var_by_num().

Here is the caller graph for this function:

◆ var2str()

const char * var2str ( anon_nasl_var * v)

Definition at line 1062 of file nasl_var.c.

1063 {
1064 if (v == NULL)
1065 return NULL;
1066
1067 if (v->string_form)
1068 return v->string_form;
1069 switch (v->var_type)
1070 {
1071 case VAR2_INT:
1072 v->string_form = g_strdup_printf ("%ld", v->v.v_int);
1073 break;
1074 case VAR2_STRING:
1075 case VAR2_DATA:
1076 v->string_form = g_malloc0 (v->v.v_str.s_siz + 1);
1077 memcpy (v->string_form,
1078 (char *) v->v.v_str.s_val ? (char *) v->v.v_str.s_val : "",
1079 v->v.v_str.s_siz + 1);
1080 break;
1081 case VAR2_UNDEF:
1082 break;
1083 case VAR2_ARRAY:
1084 v->string_form = array2str (&v->v.v_arr);
1085 break;
1086 default:
1087 v->string_form = g_strdup ("");
1088 break;
1089 }
1090 return v->string_form;
1091 }
char * array2str(const nasl_array *a)
Definition nasl_var.c:990

References array2str(), st_nasl_string::s_siz, st_nasl_string::s_val, st_a_nasl_var::string_form, 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, and st_a_nasl_var::var_type.

Referenced by dump_tree(), get_str_var_by_name(), get_str_var_by_num(), nasl_make_array(), and nasl_pread().

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

Variable Documentation

◆ nasl_trace_fp

FILE* nasl_trace_fp
extern