OpenVAS Scanner 22.7.9
nasl_var.c File Reference
#include "nasl_var.h"
#include "exec.h"
#include "nasl_debug.h"
#include "nasl_func.h"
#include "nasl_global_ctxt.h"
#include "nasl_lex_ctxt.h"
#include "nasl_tree.h"
#include <glib.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)
 
static 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 int get_var_size (const anon_nasl_var *v)
 
int get_var_size_by_name (lex_ctxt *lexic, const char *name)
 
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 813 of file nasl_var.c.

814 {
815 int h = hash_str (name);
817
818 /* Duplicated code ? */
819 for (v = lexic->ctx_vars.hash_elt[h]; v != NULL; v = v->next_var)
820 if (v->var_name != NULL && strcmp (name, v->var_name) == 0)
821 {
822 if (val != NULL)
823 nasl_perror (lexic, "Cannot add existing variable %s\n", name);
824 return NULL;
825 }
827 if (v == NULL)
828 return NULL;
829 v->next_var = lexic->ctx_vars.hash_elt[h];
830 lexic->ctx_vars.hash_elt[h] = v;
831 return v;
832 }
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:111
const char * name
Definition: nasl_init.c:411
const char * val
Definition: nasl_init.c:412
static int hash_str(const char *s)
Definition: nasl_var.c:40
static named_nasl_var * create_named_var(const char *name, tree_cell *val)
Definition: nasl_var.c:722
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
Definition: nasl_lex_ctxt.h:35

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 784 of file nasl_var.c.

785 {
786 anon_nasl_var *v;
787 nasl_array *a = &lexic->ctx_vars;
788
789 if (a->max_idx > num)
790 {
791 v = a->num_elt[num];
792 if (v != NULL && v->var_type != VAR2_UNDEF)
793 {
794 if (val != NULL)
795 nasl_perror (lexic, "Cannot add existing variable %d\n", num);
796 return NULL;
797 }
798 free_anon_var (a->num_elt[num]);
799 }
800 else
801 {
802 a->num_elt =
803 g_realloc (a->num_elt, (num + 1) * sizeof (anon_nasl_var *));
804 bzero (a->num_elt + a->max_idx,
805 sizeof (anon_nasl_var *) * (num + 1 - a->max_idx));
806 a->max_idx = num + 1;
807 }
808 a->num_elt[num] = v = create_anon_var (val);
809 return v;
810 }
static anon_nasl_var * create_anon_var(tree_cell *val)
Definition: nasl_var.c:743
static void free_anon_var(anon_nasl_var *)
Definition: nasl_var.c:387
@ VAR2_UNDEF
Definition: nasl_var.h:15
int var_type
Definition: nasl_var.h:41
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:430
#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(), and nasl_make_array().

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:469

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

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

Definition at line 554 of file nasl_var.c.

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

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 993 of file nasl_var.c.

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

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

static void clear_anon_var ( anon_nasl_var v)
static

Definition at line 406 of file nasl_var.c.

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

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

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

Definition at line 430 of file nasl_var.c.

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

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

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

Definition at line 496 of file nasl_var.c.

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

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 537 of file nasl_var.c.

538 {
539 tree_cell *c2;
540 nasl_array *a2;
541
542 if (c1 == NULL || c1 == FAKE_CELL || c1->type != REF_ARRAY)
543 return NULL;
544
546 c2->x.ref_val = a2 = g_malloc0 (sizeof (nasl_array));
547 copy_array (a2, c1->x.ref_val, 1);
548 return c2;
549 }
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:28
Definition: nasl_tree.h:94

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

static anon_nasl_var * create_anon_var ( tree_cell val)
static

Definition at line 743 of file nasl_var.c.

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

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

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

Definition at line 722 of file nasl_var.c.

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

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 774 of file nasl_var.c.

775 {
776 lex_ctxt *c = lexic;
777
778 while (c->up_ctxt != NULL)
779 c = c->up_ctxt;
780 return decl_local_variables (c, vars);
781 }
tree_cell * decl_local_variables(lex_ctxt *lexic, tree_cell *vars)
Definition: nasl_var.c:761
struct struct_lex_ctxt * up_ctxt
Definition: nasl_lex_ctxt.h:24

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 761 of file nasl_var.c.

762 {
763 tree_cell *t;
764
765 for (t = vars; t != NULL; t = t->link[0])
766 if (t->x.str_val == NULL)
767 nasl_perror (lexic, "decl_local_variables: null name!\n");
768 else
769 add_named_var_to_ctxt (lexic, t->x.str_val, NULL);
770 return FAKE_CELL;
771 }
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *lexic, const char *name, tree_cell *val)
Definition: nasl_var.c:813
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()

static anon_nasl_var * dup_anon_var ( const anon_nasl_var v)
static

Definition at line 469 of file nasl_var.c.

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

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

static named_nasl_var * dup_named_var ( const named_nasl_var v)
static

Definition at line 482 of file nasl_var.c.

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

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

static void free_anon_var ( anon_nasl_var v)
static

Definition at line 387 of file nasl_var.c.

388 {
389 if (v == NULL)
390 return;
391 switch (v->var_type)
392 {
393 case VAR2_STRING:
394 case VAR2_DATA:
395 g_free (v->v.v_str.s_val);
396 break;
397 case VAR2_ARRAY:
398 free_array (&v->v.v_arr);
399 break;
400 }
401 g_free (v->string_form);
402 g_free (v);
403 }
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 342 of file nasl_var.c.

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

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

static void free_var_chain ( named_nasl_var v)
static

Definition at line 366 of file nasl_var.c.

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

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 211 of file nasl_var.c.

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

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 1104 of file nasl_var.c.

1105 {
1106 named_nasl_var *v = get_var_ref_by_name (lexic, name, 0);
1107 return var2int (&v->u, defval);
1108 }
static long int var2int(anon_nasl_var *v, int defval)
Definition: nasl_var.c:971

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

Referenced by __attribute__(), _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_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()

◆ 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:1065

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

Referenced by __attribute__(), _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_insert_hexzeros(), nasl_keyexchg(), nasl_load_privkey_param(), nasl_mac(), nasl_match(), nasl_ntlm2_response(), nasl_ntlm_response(), nasl_ntlmv1_hash(), nasl_ntlmv2_hash(), nasl_ntlmv2_response(), nasl_ntv2_owf_gen(), 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_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()

◆ get_var_by_name()

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

Definition at line 78 of file nasl_var.c.

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

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

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

◆ get_var_name()

static const char * get_var_name ( anon_nasl_var v)
static

Definition at line 199 of file nasl_var.c.

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

Referenced by affect_to_anon_var(), and nasl_read_var_ref().

Here is the caller graph for this function:

◆ get_var_ref_by_name()

static 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 103 of file nasl_var.c.

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

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

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

Definition at line 141 of file nasl_var.c.

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

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

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

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 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 179 of file nasl_var.c.

180{
181 if (name == NULL)
182 return NULL;
183 /* Broken: Need also code in get_array_elem */
184 if (strcmp (name, "_FCT_ANON_ARGS") == 0)
185 {
187 nasl_array *a = retc->x.ref_val = g_malloc0 (sizeof (nasl_array));
188 copy_array (a, &ctxt->ctx_vars, 0);
189 return retc;
190 }
191 else
192 {
194 return var2cell (&v->u);
195 }
196 /*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(), and nasl_pread().

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

◆ hash_str()

static int hash_str ( const char *  s)
static

Definition at line 40 of file nasl_var.c.

41{
42 return hash_str2 (s, VAR_NAME_HASH);
43}
int hash_str2(const char *s, int n)
Definition: nasl_var.c:26

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 26 of file nasl_var.c.

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

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:346
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 700 of file nasl_var.c.

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

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, st_a_nasl_var::v, nasl_iterator::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 46 of file nasl_var.c.

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

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(), 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 922 of file nasl_var.c.

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

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 835 of file nasl_var.c.

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

172{
174 tc->x.ref_val = v; /* No need to free this later! */
175 return tc;
176}

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

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

Definition at line 971 of file nasl_var.c.

972 {
973 if (v == NULL)
974 return defval;
975
976 switch (v->var_type)
977 {
978 case VAR2_INT:
979 return v->v.v_int;
980
981 case VAR2_STRING:
982 case VAR2_DATA:
983 return atol ((char *) v->v.v_str.s_val);
984
985 case VAR2_UNDEF:
986 case VAR2_ARRAY:
987 default:
988 return defval;
989 }
990 /*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 1065 of file nasl_var.c.

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

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

Definition at line 357 of file exec.c.

Referenced by affect_to_anon_var(), and nasl_exec().