OpenVAS Scanner 23.43.1
exec.c File Reference
#include "exec.h"
#include "../misc/plugutils.h"
#include "lint.h"
#include "nasl.h"
#include "nasl_debug.h"
#include "nasl_func.h"
#include "nasl_global_ctxt.h"
#include "nasl_init.h"
#include "nasl_krb5.h"
#include "nasl_lex_ctxt.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <gvm/base/logging.h>
#include <gvm/base/prefs.h>
#include <gvm/util/nvticache.h>
#include <regex.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for exec.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
#define G_LOG_DOMAIN   "lib nasl"
 GLib logging domain.

Functions

int naslparse (naslctxt *, int *)
static int cell2bool (lex_ctxt *lexic, tree_cell *c)
static long int cell2int3 (lex_ctxt *lexic, tree_cell *c, int warn, named_nasl_var *v)
static long int cell2int (lex_ctxt *lexic, tree_cell *c)
static long int cell2intW (lex_ctxt *lexic, tree_cell *c)
static tree_cellint2cell (long int x)
static tree_cellbool2cell (long int x)
static char * cell2str (lex_ctxt *lexic, tree_cell *c)
tree_cellcell2atom (lex_ctxt *lexic, tree_cell *c1)
long int cell_cmp (lex_ctxt *lexic, tree_cell *c1, tree_cell *c2)
static void nasl_dump_expr (FILE *fp, const tree_cell *c)
static void nasl_short_dump (FILE *fp, const tree_cell *c)
static long int expo (long int x, long int y)
tree_cellnasl_exec (lex_ctxt *lexic, tree_cell *st)
 Execute a parse tree.
int exec_nasl_script (struct script_infos *script_infos, int mode)
 Execute a NASL script.

Variables

FILE * nasl_trace_fp = NULL
lex_ctxttruc = NULL

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 7 of file exec.c.

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib nasl"

GLib logging domain.

Definition at line 39 of file exec.c.

Function Documentation

◆ bool2cell()

tree_cell * bool2cell ( long int x)
static

Definition at line 145 of file exec.c.

146{
147 return int2cell (x != 0);
148}
static tree_cell * int2cell(long int x)
Definition exec.c:137

References int2cell().

Referenced by nasl_exec().

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

◆ cell2atom()

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

Definition at line 195 of file exec.c.

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

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

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

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

◆ cell2bool()

int cell2bool ( lex_ctxt * lexic,
tree_cell * c )
static

Definition at line 45 of file exec.c.

46{
47 tree_cell *c2;
48 int flag;
49
50 if (c == NULL || c == FAKE_CELL)
51 return 0;
52
53 switch (c->type)
54 {
55 case CONST_INT:
56 return c->x.i_val != 0;
57
58 case CONST_STR:
59 case CONST_DATA:
60 return c->size != 0;
61
62 case REF_ARRAY:
63 case DYN_ARRAY:
64 /*nasl_perror(lexic, "cell2bool: converting array to boolean does not make
65 * sense!\n"); */
66 return 1;
67
68 default:
69 c2 = nasl_exec (lexic, c);
70 flag = cell2bool (lexic, c2);
71 deref_cell (c2);
72 return flag;
73 }
74}
static int cell2bool(lex_ctxt *lexic, tree_cell *c)
Definition exec.c:45
long int i_val
Definition nasl_tree.h:104
long int size
Definition nasl_tree.h:99
union TC::@332262321161220155002104006201360276211317150140 x

References cell2bool(), CONST_DATA, CONST_INT, CONST_STR, deref_cell(), DYN_ARRAY, FAKE_CELL, TC::i_val, nasl_exec(), REF_ARRAY, TC::size, TC::type, and TC::x.

Referenced by cell2bool(), and nasl_exec().

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

◆ cell2int()

long int cell2int ( lex_ctxt * lexic,
tree_cell * c )
static

Definition at line 125 of file exec.c.

126{
127 return cell2int3 (lexic, c, 0, NULL);
128}
static long int cell2int3(lex_ctxt *lexic, tree_cell *c, int warn, named_nasl_var *v)
Definition exec.c:77

References cell2int3().

Referenced by cell_cmp(), and nasl_exec().

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

◆ cell2int3()

long int cell2int3 ( lex_ctxt * lexic,
tree_cell * c,
int warn,
named_nasl_var * v )
static

Definition at line 77 of file exec.c.

78{
79 tree_cell *c2 = NULL;
80 long int x;
81 char *p = NULL;
82
83 if (c == NULL || c == FAKE_CELL) /* Do not SEGV on undefined variables */
84 return 0;
85
86 switch (c->type)
87 {
88 case CONST_INT:
89 return c->x.i_val;
90
91 case CONST_STR:
92 case CONST_DATA:
93 x = strtol (c->x.str_val, &p, 0);
94 if (*p != '\0' && warn)
95 if (warn)
96 {
97 if (v)
98 nasl_perror (lexic,
99 "Converting the non numeric string '%s' in variable "
100 "'%s' to integer does not make sense in this "
101 "context",
102 c->x.str_val,
103 v->var_name != NULL ? v->var_name : "(null)");
104 else
105 nasl_perror (lexic,
106 "Converting the non numeric string '%s' to "
107 "integer does not make sense in this context",
108 c->x.str_val);
109 }
110 return x;
111
112 case REF_VAR:
113 v = c->x.ref_val;
114 /* fallthrough */
115
116 default:
117 c2 = nasl_exec (lexic, c);
118 x = cell2int3 (lexic, c2, warn, v);
119 deref_cell (c2);
120 return x;
121 }
122}
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition nasl_debug.c:105
@ REF_VAR
Definition nasl_tree.h:88
char * str_val
Definition nasl_tree.h:103
void * ref_val
Definition nasl_tree.h:105
char * var_name
Definition nasl_var.h:58

References cell2int3(), CONST_DATA, CONST_INT, CONST_STR, deref_cell(), FAKE_CELL, TC::i_val, nasl_exec(), nasl_perror(), TC::ref_val, REF_VAR, TC::str_val, TC::type, st_n_nasl_var::var_name, and TC::x.

Referenced by cell2int(), cell2int3(), and cell2intW().

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

◆ cell2intW()

long int cell2intW ( lex_ctxt * lexic,
tree_cell * c )
static

Definition at line 131 of file exec.c.

132{
133 return cell2int3 (lexic, c, 1, NULL);
134}

References cell2int3().

Referenced by nasl_exec().

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

◆ cell2str()

char * cell2str ( lex_ctxt * lexic,
tree_cell * c )
static

Definition at line 151 of file exec.c.

152{
153 char *p;
154 tree_cell *c2;
155 nasl_array *a;
156
157 if (c == NULL || c == FAKE_CELL)
158 return NULL;
159
160 switch (c->type)
161 {
162 case CONST_INT:
163 return g_strdup_printf ("%ld", c->x.i_val);
164
165 case CONST_STR:
166 case CONST_DATA:
167 if (c->x.str_val == NULL)
168 p = g_strdup ("");
169 else
170 {
171 p = g_malloc0 (c->size + 1);
172 memcpy (p, c->x.str_val, c->size);
173 }
174 return p;
175
176 case REF_ARRAY:
177 case DYN_ARRAY:
178 a = c->x.ref_val;
179 return array2str (a);
180
181 default:
182 c2 = nasl_exec (lexic, c);
183 p = cell2str (lexic, c2);
184 deref_cell (c2);
185 if (p == NULL)
186 p = g_strdup ("");
187 return p;
188 }
189}
static char * cell2str(lex_ctxt *lexic, tree_cell *c)
Definition exec.c:151
char * array2str(const nasl_array *a)
Definition nasl_var.c:990
struct st_nasl_array nasl_array

References array2str(), cell2str(), CONST_DATA, CONST_INT, CONST_STR, deref_cell(), DYN_ARRAY, FAKE_CELL, TC::i_val, nasl_exec(), REF_ARRAY, TC::ref_val, TC::size, TC::str_val, TC::type, and TC::x.

Referenced by cell2str(), cell_cmp(), and nasl_exec().

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

◆ cell_cmp()

long int cell_cmp ( lex_ctxt * lexic,
tree_cell * c1,
tree_cell * c2 )

Definition at line 219 of file exec.c.

220{
221 int flag, typ, typ1, typ2;
222 long int x1, x2;
223 char *s1, *s2;
224 int len_s1, len_s2, len_min;
225
226 if (c1 == NULL || c1 == FAKE_CELL)
227 nasl_perror (lexic, "cell_cmp: c1 == NULL !\n");
228 if (c2 == NULL || c2 == FAKE_CELL)
229 nasl_perror (lexic, "cell_cmp: c2 == NULL !\n");
230
231 /* We first convert the cell to atomic types. */
232 c1 = cell2atom (lexic, c1);
233 c2 = cell2atom (lexic, c2);
234
235 /*
236 * Comparing anything to something else which is entirely different
237 * may lead to unpredictable results.
238 * Here are the rules:
239 * 1. No problem with same types, although we do not compare arrays yet
240 * 2. No problem with CONST_DATA / CONST_STR
241 * 3. When an integer is compared to a string, the integer is converted
242 * 4. When NULL is compared to an integer, it is converted to 0
243 * 5. When NULL is compared to a string, it is converted to ""
244 * 6. NULL is "smaller" than anything else (i.e. an array)
245 * Anything else is an error
246 */
247 typ1 = cell_type (c1);
248 typ2 = cell_type (c2);
249
250 if (typ1 == 0 && typ2 == 0) /* Two NULL */
251 {
252 deref_cell (c1);
253 deref_cell (c2);
254 return 0;
255 }
256
257 if (typ1 == typ2) /* Same type, no problem */
258 typ = typ1;
259 else if ((typ1 == CONST_DATA || typ1 == CONST_STR)
260 && (typ2 == CONST_DATA || typ2 == CONST_STR))
261 typ = CONST_DATA; /* Same type in fact (string) */
262 /* We convert an integer into a string before compare */
263 else if ((typ1 == CONST_INT && (typ2 == CONST_DATA || typ2 == CONST_STR))
264 || (typ2 == CONST_INT && (typ1 == CONST_DATA || typ1 == CONST_STR)))
265 typ = CONST_DATA;
266 else if (typ1 == 0) /* 1st argument is null */
267 if (typ2 == CONST_INT || typ2 == CONST_DATA || typ2 == CONST_STR)
268 typ = typ2; /* We convert it to 0 or "" */
269 else
270 {
271 deref_cell (c1);
272 deref_cell (c2);
273 return -1; /* NULL is smaller than anything else */
274 }
275 else if (typ2 == 0) /* 2nd argument is null */
276 if (typ1 == CONST_INT || typ1 == CONST_DATA || typ1 == CONST_STR)
277 typ = typ1; /* We convert it to 0 or "" */
278 else
279 {
280 deref_cell (c1);
281 deref_cell (c2);
282 return 1; /* Anything else is greater than NULL */
283 }
284 else
285 {
286 gchar *n1, *n2;
287
288 n1 = cell2str (lexic, c1);
289 n2 = cell2str (lexic, c2);
290 nasl_perror (lexic,
291 "cell_cmp: comparing '%s' of type %s and '%s' of "
292 "type %s does not make sense\n",
293 n1, nasl_type_name (typ1), n2, nasl_type_name (typ2));
294 g_free (n1);
295 g_free (n2);
296 deref_cell (c1);
297 deref_cell (c2);
298 return 0;
299 }
300
301 switch (typ)
302 {
303 case CONST_INT:
304 x1 = cell2int (lexic, c1);
305 x2 = cell2int (lexic, c2);
306 deref_cell (c1);
307 deref_cell (c2);
308 return x1 - x2;
309
310 case CONST_STR:
311 case CONST_DATA:
312 s1 = cell2str (lexic, c1);
313 if (typ1 == CONST_STR || typ1 == CONST_DATA)
314 len_s1 = c1->size;
315 else if (s1 == NULL)
316 len_s1 = 0;
317 else
318 len_s1 = strlen (s1);
319
320 s2 = cell2str (lexic, c2);
321 if (typ2 == CONST_STR || typ2 == CONST_DATA)
322 len_s2 = c2->size;
323 else if (s2 == NULL)
324 len_s2 = 0;
325 else
326 len_s2 = strlen (s2);
327
328 len_min = len_s1 < len_s2 ? len_s1 : len_s2;
329 flag = 0;
330
331 if (len_min > 0)
332 flag = memcmp (s1, s2, len_min);
333 if (flag == 0)
334 flag = len_s1 - len_s2;
335
336 g_free (s1);
337 g_free (s2);
338 deref_cell (c1);
339 deref_cell (c2);
340 return flag;
341
342 case REF_ARRAY:
343 case DYN_ARRAY:
344 g_message ("cell_cmp: cannot compare arrays yet");
345 deref_cell (c1);
346 deref_cell (c2);
347 return 0;
348
349 default:
350 g_message ("cell_cmp: don't known how to compare %s and %s",
351 nasl_type_name (typ1), nasl_type_name (typ2));
352 deref_cell (c1);
353 deref_cell (c2);
354 return 0;
355 }
356}
static long int cell2int(lex_ctxt *lexic, tree_cell *c)
Definition exec.c:125
int cell_type(const tree_cell *c)
Definition nasl_tree.c:404
const char * nasl_type_name(int t)
Definition nasl_tree.c:343

References cell2atom(), cell2int(), cell2str(), cell_type(), CONST_DATA, CONST_INT, CONST_STR, deref_cell(), DYN_ARRAY, FAKE_CELL, nasl_perror(), nasl_type_name(), REF_ARRAY, and TC::size.

Referenced by nasl_exec(), and var_cmp().

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

◆ exec_nasl_script()

int exec_nasl_script ( struct script_infos * script_infos,
int mode )

Execute a NASL script.

"mode" is a bit field: bit #0 (1) is "description" Bit #1 (2) is "parse only"

Parameters
script_infosThe plugin script_infos. #param mode Flags for different execution modes (Description, parse-only, always-signed, command-line, lint)
Returns
0 if the script was executed successfully, negative values if an error occurred. Return number of errors if mode is NASL_LINT and no none linting errors occurred.

Definition at line 1615 of file exec.c.

1616{
1617 naslctxt ctx;
1618 nasl_func *pf;
1619 int err = 0, to;
1620 tree_cell *ret;
1621 lex_ctxt *lexic;
1622 gchar *old_dir;
1623 gchar *newdir;
1624 tree_cell tc;
1625 const char *str, *name = script_infos->name, *oid = script_infos->oid;
1626 gchar *short_name = g_path_get_basename (name);
1627 int error_counter = 0;
1628
1629 nasl_set_plugin_filename (short_name);
1630 g_free (short_name);
1631
1632 srand48 (getpid () + getppid () + (long) time (NULL));
1633
1634 old_dir = g_get_current_dir ();
1635
1636 newdir = g_path_get_dirname (name);
1637
1638 if (g_chdir (newdir) != 0)
1639 {
1640 g_message ("%s: Not able to change working directory to %s (%d [%s]).",
1641 __func__, newdir, errno, strerror (errno));
1642 g_free (old_dir);
1643 g_free (newdir);
1644 return -1;
1645 }
1646 g_free (newdir);
1647
1648 bzero (&ctx, sizeof (ctx));
1649 if (mode & NASL_ALWAYS_SIGNED)
1650 ctx.always_signed = 1;
1651 if ((mode & NASL_EXEC_DESCR) != 0)
1652 ctx.exec_descr = 1;
1653 if (nvticache_initialized ())
1654 ctx.kb = nvticache_get_kb ();
1655 else
1656 ctx.kb = plug_get_kb (script_infos);
1657
1658 if (init_nasl_ctx (&ctx, NULL, name) == 0)
1659 {
1660 err = naslparse (&ctx, &error_counter);
1661 if (err != 0 || error_counter > 0)
1662 {
1663 g_message ("%s. There were %d parse errors.", name, error_counter);
1664 nasl_clean_ctx (&ctx);
1665 g_chdir (old_dir);
1666 g_free (old_dir);
1667 return -1;
1668 }
1669 }
1670 else
1671 {
1672 g_chdir (old_dir);
1673 g_free (old_dir);
1674 return -1;
1675 }
1676
1677 lexic = init_empty_lex_ctxt ();
1678 lexic->script_infos = script_infos;
1679 lexic->oid = oid;
1681
1682 str = prefs_get ("checks_read_timeout");
1683 if (str != NULL)
1684 to = atoi (str);
1685 else
1686 to = 5;
1687
1688 if (to <= 0)
1689 to = 5;
1690
1691 lexic->recv_timeout = to;
1692
1693 if (mode & NASL_LINT)
1694 {
1695 /* ret is set to the number of errors the linter finds.
1696 ret will be overwritten with -1 if any errors occur in the steps
1697 after linting so we do not break other behaviour dependent on a
1698 negative return value when doing more than just linting. */
1699 tree_cell *lintret = nasl_lint (lexic, ctx.tree);
1700 if (lintret == NULL)
1701 err--;
1702 else if (lintret != FAKE_CELL && lintret->x.i_val > 0)
1703 {
1704 err = lintret->x.i_val;
1705 g_free (lintret);
1706 }
1707 }
1708 else if (!(mode & NASL_EXEC_PARSE_ONLY))
1709 {
1710 char *p, *name_aux;
1711
1712 bzero (&tc, sizeof (tc));
1713 tc.type = CONST_INT;
1714 tc.x.i_val = (mode & NASL_COMMAND_LINE) != 0;
1715 add_named_var_to_ctxt (lexic, "COMMAND_LINE", &tc);
1716
1717 bzero (&tc, sizeof (tc));
1718 tc.type = CONST_INT;
1719 tc.x.i_val = (mode & NASL_EXEC_DESCR) != 0;
1720 add_named_var_to_ctxt (lexic, "description", &tc);
1721
1722 tc.type = CONST_DATA;
1723 // for preserving the const qualifier during assignment
1724 name_aux = g_strdup (name);
1725 p = strrchr (name_aux, '/');
1726 if (p == NULL)
1727 p = (char *) name_aux;
1728 else
1729 p++;
1730
1731 tc.x.str_val = p;
1732 tc.size = strlen (p);
1733 add_named_var_to_ctxt (lexic, "SCRIPT_NAME", &tc);
1734 g_free (name_aux);
1735
1736 truc = (lex_ctxt *) ctx.tree;
1737 if ((ret = nasl_exec (lexic, ctx.tree)) == NULL)
1738 err = -1;
1739 else
1740 deref_cell (ret);
1741
1742 if ((pf = get_func_ref_by_name (lexic, "on_exit")) != NULL)
1743 nasl_func_call (lexic, pf, NULL);
1744
1745 }
1746
1747 if (g_chdir (old_dir) != 0)
1748 {
1749 g_free (old_dir);
1750 return -1;
1751 }
1752 g_free (old_dir);
1753
1755 nasl_clean_ctx (&ctx);
1756 free_lex_ctxt (lexic);
1757 return err;
1758}
int naslparse(naslctxt *, int *)
lex_ctxt * truc
Definition exec.c:360
tree_cell * nasl_lint(lex_ctxt *lexic, tree_cell *st)
Search for errors in a nasl script.
Definition lint.c:811
#define NASL_ALWAYS_SIGNED
Definition nasl.h:47
#define NASL_EXEC_DESCR
Definition nasl.h:45
#define NASL_EXEC_PARSE_ONLY
Definition nasl.h:46
#define NASL_COMMAND_LINE
Definition nasl.h:48
#define NASL_LINT
Definition nasl.h:49
const char * oid
void nasl_set_filename(const char *filename)
Definition nasl_debug.c:82
void nasl_set_plugin_filename(const char *filename)
Set the current launched plugin filename.
Definition nasl_debug.c:47
tree_cell * nasl_func_call(lex_ctxt *lexic, const nasl_func *f, tree_cell *arg_list)
Definition nasl_func.c:95
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
Definition nasl_func.c:82
struct st_nasl_func nasl_func
int init_nasl_ctx(naslctxt *, const char *, const char *)
Initialize a NASL context for a NASL file.
void nasl_clean_ctx(naslctxt *)
const char * name
Definition nasl_init.c:440
void nasl_okrb5_clean(void)
Definition nasl_krb5.c:340
void free_lex_ctxt(lex_ctxt *c)
lex_ctxt * init_empty_lex_ctxt()
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *, const char *, tree_cell *)
Definition nasl_var.c:810
struct struct_lex_ctxt lex_ctxt
kb_t plug_get_kb(struct script_infos *args)
Definition plugutils.c:1157
tree_cell * tree
char * name
Definition scanneraux.h:35
struct script_infos * script_infos
const char * oid

References add_named_var_to_ctxt(), naslctxt::always_signed, CONST_DATA, CONST_INT, deref_cell(), naslctxt::exec_descr, FAKE_CELL, free_lex_ctxt(), get_func_ref_by_name(), TC::i_val, init_empty_lex_ctxt(), init_nasl_ctx(), naslctxt::kb, name, script_infos::name, NASL_ALWAYS_SIGNED, nasl_clean_ctx(), NASL_COMMAND_LINE, nasl_exec(), NASL_EXEC_DESCR, NASL_EXEC_PARSE_ONLY, nasl_func_call(), NASL_LINT, nasl_lint(), nasl_okrb5_clean(), nasl_set_filename(), nasl_set_plugin_filename(), naslparse(), oid, script_infos::oid, struct_lex_ctxt::oid, plug_get_kb(), struct_lex_ctxt::recv_timeout, struct_lex_ctxt::script_infos, TC::size, TC::str_val, naslctxt::tree, truc, TC::type, and TC::x.

Referenced by main(), nasl_file_check(), nasl_plugin_add(), nasl_thread(), parse_script_infos(), and process_file().

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

◆ expo()

long int expo ( long int x,
long int y )
static
Todo
This is an algorithm for calculating x^y, replace it if possible.

Definition at line 746 of file exec.c.

747{
748 long int z;
749
750 if (y == 0)
751 return 1;
752 else if (y < 0)
753 if (x == 1)
754 return 1;
755 else
756 return 0;
757 else if (y == 1)
758 return x;
759
760 z = expo (x, y / 2);
761 if (y % 2 == 0)
762 return z * z;
763 else
764 return x * z * z;
765}
static long int expo(long int x, long int y)
Definition exec.c:746

References expo().

Referenced by expo(), and nasl_exec().

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

◆ int2cell()

tree_cell * int2cell ( long int x)
static

Definition at line 137 of file exec.c.

138{
139 tree_cell *c = alloc_expr_cell (0, CONST_INT, NULL, NULL);
140 c->x.i_val = x;
141 return c;
142}
tree_cell * alloc_expr_cell(int lnb, int t, tree_cell *l, tree_cell *r)
Definition nasl_tree.c:60

References alloc_expr_cell(), CONST_INT, TC::i_val, and TC::x.

Referenced by bool2cell(), and nasl_exec().

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

◆ nasl_dump_expr()

void nasl_dump_expr ( FILE * fp,
const tree_cell * c )
static
Todo
Refactor, remove upcoming code duplicates.

Definition at line 363 of file exec.c.

364{
365 if (c == NULL)
366 fprintf (fp, "NULL");
367 else if (c == FAKE_CELL)
368 fprintf (fp, "FAKE");
369 else
370 switch (c->type)
371 {
372 case NODE_VAR:
373 fprintf (fp, "%s", c->x.str_val);
374 break;
375 case EXPR_AND:
376 fprintf (fp, "(");
377 nasl_dump_expr (fp, c->link[0]);
378 fprintf (fp, ") && (");
379 nasl_dump_expr (fp, c->link[1]);
380 fprintf (fp, ")");
381 break;
382 case EXPR_OR:
383 fprintf (fp, "(");
384 nasl_dump_expr (fp, c->link[0]);
385 fprintf (fp, ") || (");
386 nasl_dump_expr (fp, c->link[1]);
387 fprintf (fp, ")");
388 break;
389 case EXPR_NOT:
390 fprintf (fp, "! (");
391 nasl_dump_expr (fp, c->link[0]);
392 fprintf (fp, ")");
393 break;
394 case EXPR_PLUS:
395 fprintf (fp, "(");
396 nasl_dump_expr (fp, c->link[0]);
397 fprintf (fp, ") + (");
398 nasl_dump_expr (fp, c->link[1]);
399 fprintf (fp, ")");
400 break;
401 case EXPR_MINUS:
402 fprintf (fp, "(");
403 nasl_dump_expr (fp, c->link[0]);
404 fprintf (fp, ") - (");
405 nasl_dump_expr (fp, c->link[1]);
406 fprintf (fp, ")");
407 break;
408
409 case EXPR_INCR:
410 if (c->link[0] == NULL)
411 {
412 fprintf (fp, " ++");
413 nasl_dump_expr (fp, c->link[1]);
414 }
415 else
416 {
417 nasl_dump_expr (fp, c->link[0]);
418 fprintf (fp, "++ ");
419 }
420 break;
421 case EXPR_DECR:
422 if (c->link[0] == NULL)
423 {
424 fprintf (fp, " --");
425 nasl_dump_expr (fp, c->link[1]);
426 }
427 else
428 {
429 nasl_dump_expr (fp, c->link[0]);
430 fprintf (fp, "-- ");
431 }
432 break;
433
435 case EXPR_EXPO:
436 fprintf (fp, "(");
437 nasl_dump_expr (fp, c->link[0]);
438 fprintf (fp, ") ** (");
439 nasl_dump_expr (fp, c->link[1]);
440 fprintf (fp, ")");
441 break;
442
443 case EXPR_U_MINUS:
444 fprintf (fp, " - (");
445 nasl_dump_expr (fp, c->link[0]);
446 fprintf (fp, ")");
447 break;
448
449 case EXPR_MULT:
450 fprintf (fp, "(");
451 nasl_dump_expr (fp, c->link[0]);
452 fprintf (fp, ") * (");
453 nasl_dump_expr (fp, c->link[1]);
454 fprintf (fp, ")");
455 break;
456 case EXPR_DIV:
457 fprintf (fp, "(");
458 nasl_dump_expr (fp, c->link[0]);
459 fprintf (fp, ") / (");
460 nasl_dump_expr (fp, c->link[1]);
461 fprintf (fp, ")");
462 break;
463 case EXPR_MODULO:
464 fprintf (fp, "(");
465 nasl_dump_expr (fp, c->link[0]);
466 fprintf (fp, ") %% (");
467 nasl_dump_expr (fp, c->link[1]);
468 fprintf (fp, ")");
469 break;
470 case EXPR_BIT_AND:
471 fprintf (fp, "(");
472 nasl_dump_expr (fp, c->link[0]);
473 fprintf (fp, ") & (");
474 nasl_dump_expr (fp, c->link[1]);
475 fprintf (fp, ")");
476 break;
477 case EXPR_BIT_OR:
478 fprintf (fp, "(");
479 nasl_dump_expr (fp, c->link[0]);
480 fprintf (fp, ") | (");
481 nasl_dump_expr (fp, c->link[1]);
482 fprintf (fp, ")");
483 break;
484 case EXPR_BIT_XOR:
485 fprintf (fp, "(");
486 nasl_dump_expr (fp, c->link[0]);
487 fprintf (fp, ") ^ (");
488 nasl_dump_expr (fp, c->link[1]);
489 fprintf (fp, ")");
490 break;
491 case EXPR_BIT_NOT:
492 fprintf (fp, "~ (");
493 nasl_dump_expr (fp, c->link[0]);
494 fprintf (fp, ")");
495 break;
496 case EXPR_L_SHIFT:
497 fprintf (fp, "(");
498 nasl_dump_expr (fp, c->link[0]);
499 fprintf (fp, ") << (");
500 nasl_dump_expr (fp, c->link[1]);
501 fprintf (fp, ")");
502 break;
503 case EXPR_R_SHIFT:
504 fprintf (fp, "(");
505 nasl_dump_expr (fp, c->link[0]);
506 fprintf (fp, ") >> (");
507 nasl_dump_expr (fp, c->link[1]);
508 fprintf (fp, ")");
509 break;
510 case EXPR_R_USHIFT:
511 fprintf (fp, "(");
512 nasl_dump_expr (fp, c->link[0]);
513 fprintf (fp, ") >>> (");
514 nasl_dump_expr (fp, c->link[1]);
515 fprintf (fp, ")");
516 break;
517 case COMP_MATCH:
518 nasl_dump_expr (fp, c->link[0]);
519 fprintf (fp, " >< ");
520 nasl_dump_expr (fp, c->link[1]);
521 break;
522 case COMP_NOMATCH:
523 nasl_dump_expr (fp, c->link[0]);
524 fprintf (fp, " >!< ");
525 nasl_dump_expr (fp, c->link[1]);
526 break;
527
528 case COMP_RE_MATCH:
529 nasl_dump_expr (fp, c->link[0]);
530 fprintf (fp, " =~ ");
531 nasl_dump_expr (fp, c->link[1]);
532 break;
533
534 case COMP_RE_NOMATCH:
535 nasl_dump_expr (fp, c->link[0]);
536 fprintf (fp, " !~ ");
537 nasl_dump_expr (fp, c->link[1]);
538 break;
539
540 case COMP_LT:
541 nasl_dump_expr (fp, c->link[0]);
542 fprintf (fp, " < ");
543 nasl_dump_expr (fp, c->link[1]);
544 break;
545 case COMP_LE:
546 nasl_dump_expr (fp, c->link[0]);
547 fprintf (fp, " <= ");
548 nasl_dump_expr (fp, c->link[1]);
549 break;
550 case COMP_GT:
551 nasl_dump_expr (fp, c->link[0]);
552 fprintf (fp, " > ");
553 nasl_dump_expr (fp, c->link[1]);
554 break;
555 case COMP_GE:
556 nasl_dump_expr (fp, c->link[0]);
557 fprintf (fp, " >= ");
558 nasl_dump_expr (fp, c->link[1]);
559 break;
560 case COMP_EQ:
561 nasl_dump_expr (fp, c->link[0]);
562 fprintf (fp, " == ");
563 nasl_dump_expr (fp, c->link[1]);
564 break;
565 case CONST_INT:
566 fprintf (fp, "%ld", c->x.i_val);
567 break;
568 case CONST_STR:
569 case CONST_DATA:
570 fprintf (fp, "\"%s\"", c->x.str_val);
571 break;
572
573 case NODE_ARRAY_EL:
574 fprintf (fp, "%s[", c->x.str_val);
575 nasl_dump_expr (fp, c->link[0]);
576 fprintf (fp, "]");
577 break;
578
579 case NODE_FUN_CALL:
580 fprintf (fp, "%s(...)", c->x.str_val);
581 break;
582
583 case NODE_AFF:
584 nasl_dump_expr (fp, c->link[0]);
585 putc ('=', fp);
586 nasl_dump_expr (fp, c->link[1]);
587 break;
588
589 case NODE_PLUS_EQ:
590 nasl_dump_expr (fp, c->link[0]);
591 fprintf (fp, "+= (");
592 nasl_dump_expr (fp, c->link[1]);
593 fprintf (fp, ")");
594 break;
595
596 case NODE_MINUS_EQ:
597 nasl_dump_expr (fp, c->link[0]);
598 fprintf (fp, "-= (");
599 nasl_dump_expr (fp, c->link[1]);
600 fprintf (fp, ")");
601 break;
602
603 case NODE_MULT_EQ:
604 nasl_dump_expr (fp, c->link[0]);
605 fprintf (fp, "*= (");
606 nasl_dump_expr (fp, c->link[1]);
607 fprintf (fp, ")");
608 break;
609
610 case NODE_DIV_EQ:
611 nasl_dump_expr (fp, c->link[0]);
612 fprintf (fp, "/= (");
613 nasl_dump_expr (fp, c->link[1]);
614 fprintf (fp, ")");
615 break;
616
617 case NODE_MODULO_EQ:
618 nasl_dump_expr (fp, c->link[0]);
619 fprintf (fp, "%%= (");
620 nasl_dump_expr (fp, c->link[1]);
621 fprintf (fp, ")");
622 break;
623
624 case NODE_L_SHIFT_EQ:
625 nasl_dump_expr (fp, c->link[0]);
626 fprintf (fp, " <<= (");
627 nasl_dump_expr (fp, c->link[1]);
628 fprintf (fp, ")");
629 break;
630
631 case NODE_R_SHIFT_EQ:
632 nasl_dump_expr (fp, c->link[0]);
633 fprintf (fp, " >>= (");
634 nasl_dump_expr (fp, c->link[1]);
635 fprintf (fp, ")");
636 break;
637
638 case NODE_R_USHIFT_EQ:
639 nasl_dump_expr (fp, c->link[0]);
640 fprintf (fp, " >>>= (");
641 nasl_dump_expr (fp, c->link[1]);
642 fprintf (fp, ")");
643 break;
644
645 default:
646 fprintf (fp, "*%d*", c->type);
647 break;
648 }
649}
static void nasl_dump_expr(FILE *fp, const tree_cell *c)
Definition exec.c:363
@ NODE_ARRAY_EL
Definition nasl_tree.h:29
@ NODE_L_SHIFT_EQ
Definition nasl_tree.h:41
@ NODE_PLUS_EQ
Definition nasl_tree.h:35
@ NODE_FUN_CALL
Definition nasl_tree.h:22
@ COMP_LE
Definition nasl_tree.h:73
@ NODE_R_SHIFT_EQ
Definition nasl_tree.h:42
@ COMP_GT
Definition nasl_tree.h:76
@ NODE_AFF
Definition nasl_tree.h:30
@ EXPR_MODULO
Definition nasl_tree.h:54
@ COMP_RE_MATCH
Definition nasl_tree.h:69
@ NODE_MULT_EQ
Definition nasl_tree.h:37
@ NODE_VAR
Definition nasl_tree.h:31
@ NODE_R_USHIFT_EQ
Definition nasl_tree.h:43
@ COMP_EQ
Definition nasl_tree.h:74
@ EXPR_MULT
Definition nasl_tree.h:52
@ COMP_GE
Definition nasl_tree.h:77
@ EXPR_BIT_NOT
Definition nasl_tree.h:60
@ EXPR_R_SHIFT
Definition nasl_tree.h:64
@ EXPR_DIV
Definition nasl_tree.h:53
@ COMP_RE_NOMATCH
Definition nasl_tree.h:70
@ EXPR_BIT_XOR
Definition nasl_tree.h:59
@ NODE_DIV_EQ
Definition nasl_tree.h:38
@ NODE_MINUS_EQ
Definition nasl_tree.h:36
@ COMP_NOMATCH
Definition nasl_tree.h:68
@ COMP_MATCH
Definition nasl_tree.h:67
@ EXPR_NOT
Definition nasl_tree.h:47
@ EXPR_PLUS
Definition nasl_tree.h:49
@ EXPR_L_SHIFT
Definition nasl_tree.h:63
@ EXPR_BIT_AND
Definition nasl_tree.h:57
@ EXPR_EXPO
Definition nasl_tree.h:55
@ EXPR_INCR
Definition nasl_tree.h:61
@ EXPR_BIT_OR
Definition nasl_tree.h:58
@ EXPR_U_MINUS
Definition nasl_tree.h:51
@ COMP_LT
Definition nasl_tree.h:72
@ EXPR_OR
Definition nasl_tree.h:46
@ EXPR_DECR
Definition nasl_tree.h:62
@ EXPR_R_USHIFT
Definition nasl_tree.h:65
@ EXPR_MINUS
Definition nasl_tree.h:50
@ NODE_MODULO_EQ
Definition nasl_tree.h:39
@ EXPR_AND
Definition nasl_tree.h:45
struct TC * link[4]
Definition nasl_tree.h:107

References COMP_EQ, COMP_GE, COMP_GT, COMP_LE, COMP_LT, COMP_MATCH, COMP_NOMATCH, COMP_RE_MATCH, COMP_RE_NOMATCH, CONST_DATA, CONST_INT, CONST_STR, EXPR_AND, EXPR_BIT_AND, EXPR_BIT_NOT, EXPR_BIT_OR, EXPR_BIT_XOR, EXPR_DECR, EXPR_DIV, EXPR_EXPO, EXPR_INCR, EXPR_L_SHIFT, EXPR_MINUS, EXPR_MODULO, EXPR_MULT, EXPR_NOT, EXPR_OR, EXPR_PLUS, EXPR_R_SHIFT, EXPR_R_USHIFT, EXPR_U_MINUS, FAKE_CELL, TC::i_val, TC::link, nasl_dump_expr(), NODE_AFF, NODE_ARRAY_EL, NODE_DIV_EQ, NODE_FUN_CALL, NODE_L_SHIFT_EQ, NODE_MINUS_EQ, NODE_MODULO_EQ, NODE_MULT_EQ, NODE_PLUS_EQ, NODE_R_SHIFT_EQ, NODE_R_USHIFT_EQ, NODE_VAR, TC::str_val, TC::type, and TC::x.

Referenced by nasl_dump_expr(), and nasl_short_dump().

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

◆ nasl_exec()

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

Execute a parse tree.

Todo
There is a lot of duplicated code in following cases, could be refactored.

Definition at line 771 of file exec.c.

772{
773 tree_cell *ret = NULL, *ret2 = NULL, *tc1 = NULL, *tc2 = NULL, *tc3 = NULL,
774 *idx = NULL, *args;
775 int flag, z;
776 char *s1 = NULL, *s2 = NULL, *s3 = NULL, *p = NULL;
777 char *p1, *p2;
778 int len1, len2;
779 nasl_func *pf = NULL;
780 long int x, y, n;
781 int i, lint_mode = 0;
782
783 if (st)
784 if (st->line_nb != 0)
785 lexic->line_nb = st->line_nb;
786 /* return */
787 if (lexic->ret_val != NULL)
788 {
789 ref_cell (lexic->ret_val);
790 return lexic->ret_val;
791 }
792
793 /* break or continue */
794 if (lexic->break_flag || lexic->cont_flag)
795 return FAKE_CELL;
796
797 if (st == FAKE_CELL)
798 return FAKE_CELL;
799
800 if (st == NULL)
801 {
802 return NULL;
803 }
804
805 if (nasl_trace_fp != NULL)
807
808 switch (st->type)
809 {
810 case NODE_IF_ELSE:
811 ret = nasl_exec (lexic, st->link[0]);
812#ifdef STOP_AT_FIRST_ERROR
813 if (ret == NULL)
814 return NULL;
815#endif
816 if (cell2bool (lexic, ret))
817 ret2 = nasl_exec (lexic, st->link[1]);
818 else if (st->link[2] != NULL) /* else branch */
819 ret2 = nasl_exec (lexic, st->link[2]);
820 else /* No else */
821 ret2 = FAKE_CELL;
822 deref_cell (ret);
823 return ret2;
824
825 case NODE_INSTR_L: /* Block. [0] = first instr, [1] = tail */
826 ret = nasl_exec (lexic, st->link[0]);
827 if (st->link[1] == NULL || lexic->break_flag || lexic->cont_flag)
828 return ret;
829 deref_cell (ret);
830 ret = nasl_exec (lexic, st->link[1]);
831 return ret;
832
833 case NODE_FOR:
834 /* [0] = start expr, [1] = cond, [2] = end_expr, [3] = block */
835 ret2 = nasl_exec (lexic, st->link[0]);
836#ifdef STOP_AT_FIRST_ERROR
837 if (ret2 == NULL)
838 return NULL;
839#endif
840 deref_cell (ret2);
841 for (;;)
842 {
843 /* Break the loop if 'return' */
844 if (lexic->ret_val != NULL)
845 {
846 ref_cell (lexic->ret_val);
847 return lexic->ret_val;
848 }
849
850 /* condition */
851 if ((ret = nasl_exec (lexic, st->link[1])) == NULL)
852 return NULL; /* We can return here, as NULL is false */
853 flag = cell2bool (lexic, ret);
854 deref_cell (ret);
855 if (!flag)
856 break;
857 /* block */
858 ret = nasl_exec (lexic, st->link[3]);
859#ifdef STOP_AT_FIRST_ERROR
860 if (ret == NULL)
861 return NULL;
862#endif
863 deref_cell (ret);
864
865 /* break */
866 if (lexic->break_flag)
867 {
868 lexic->break_flag = 0;
869 return FAKE_CELL;
870 }
871
872 lexic->cont_flag = 0; /* No need to test if set */
873
874 /* end expression */
875 ret = nasl_exec (lexic, st->link[2]);
876#ifdef STOP_AT_FIRST_ERROR
877 if (ret == NULL)
878 return NULL;
879#endif
880 deref_cell (ret);
881 }
882 return FAKE_CELL;
883
884 case NODE_WHILE:
885 /* [0] = cond, [1] = block */
886 for (;;)
887 {
888 /* return? */
889 if (lexic->ret_val != NULL)
890 {
891 ref_cell (lexic->ret_val);
892 return lexic->ret_val;
893 }
894 /* Condition */
895 if ((ret = nasl_exec (lexic, st->link[0])) == NULL)
896 return NULL; /* NULL is false */
897 flag = cell2bool (lexic, ret);
898 deref_cell (ret);
899 if (!flag)
900 break;
901 /* Block */
902 ret = nasl_exec (lexic, st->link[1]);
903#ifdef STOP_AT_FIRST_ERROR
904 if (ret == NULL)
905 return NULL;
906#endif
907 deref_cell (ret);
908
909 /* break */
910 if (lexic->break_flag)
911 {
912 lexic->break_flag = 0;
913 return FAKE_CELL;
914 }
915 lexic->cont_flag = 0;
916 }
917 return FAKE_CELL;
918
920 /* [0] = block, [1] = cond */
921 for (;;)
922 {
923 /* return? */
924 if (lexic->ret_val != NULL)
925 {
926 ref_cell (lexic->ret_val);
927 return lexic->ret_val;
928 }
929 /* Block */
930 ret = nasl_exec (lexic, st->link[0]);
931#ifdef STOP_AT_FIRST_ERROR
932 if (ret == NULL)
933 return NULL;
934#endif
935 deref_cell (ret);
936
937 /* break */
938 if (lexic->break_flag)
939 {
940 lexic->break_flag = 0;
941 return FAKE_CELL;
942 }
943 lexic->cont_flag = 0;
944
945 /* Condition */
946 ret = nasl_exec (lexic, st->link[1]);
947#ifdef STOP_AT_FIRST_ERROR
948 if (ret == NULL)
949 return NULL;
950#endif
951 flag = cell2bool (lexic, ret);
952 deref_cell (ret);
953 if (flag)
954 break;
955 }
956 return FAKE_CELL;
957
958 case NODE_FOREACH:
959 /* str_val = index name, [0] = array, [1] = block */
960 {
961 nasl_iterator ai;
962 tree_cell *v, *a, *val;
963
964 v = get_variable_by_name (lexic, st->x.str_val);
965 if (v == NULL)
966 return NULL; /* We cannot go on if we have no variable to iterate */
967 a = nasl_exec (lexic, st->link[0]);
968 ai = nasl_array_iterator (lexic, a);
969 while ((val = nasl_iterate_array (&ai)) != NULL)
970 {
971 tc1 = nasl_affect (v, val);
972 ret = nasl_exec (lexic, st->link[1]);
973 deref_cell (val);
974 deref_cell (tc1);
975#ifdef STOP_AT_FIRST_ERROR
976 if (ret == NULL)
977 break;
978#endif
979 deref_cell (ret);
980
981 /* return */
982 if (lexic->ret_val != NULL)
983 break;
984 /* break */
985 if (lexic->break_flag)
986 {
987 lexic->break_flag = 0;
988 break;
989 }
990 lexic->cont_flag = 0;
991 }
992 free_array (ai.a);
993 g_free (ai.a);
994 deref_cell (a);
995 deref_cell (v);
996 }
997 return FAKE_CELL;
998
999 case NODE_FUN_DEF:
1000 /* x.str_val = function name, [0] = argdecl, [1] = block */
1001 /* 3rd arg is only for lint. Hier is always 0 */
1002 ret = decl_nasl_func (lexic, st, lint_mode);
1003 return ret;
1004
1005 case NODE_FUN_CALL:
1006 pf = get_func_ref_by_name (lexic, st->x.str_val);
1007 if (pf == NULL)
1008 {
1009 nasl_perror (lexic, "Undefined function '%s'\n", st->x.str_val);
1010 return NULL;
1011 }
1012 args = st->link[0];
1013 ret = nasl_func_call (lexic, pf, args);
1014 return ret;
1015
1016 case NODE_REPEATED:
1017 n = cell2intW (lexic, st->link[1]);
1018 if (n <= 0)
1019 return NULL;
1020
1021#ifdef STOP_AT_FIRST_ERROR
1022 for (tc1 = NULL, i = 1; i <= n; i++)
1023 {
1024 deref_cell (tc1);
1025 if ((tc1 = nasl_exec (lexic, st->link[0])) == NULL)
1026 return NULL;
1027 }
1028 return tc1;
1029#else
1030 for (i = 1; i <= n; i++)
1031 {
1032 tc1 = nasl_exec (lexic, st->link[0]);
1033 deref_cell (tc1);
1034 }
1035 return FAKE_CELL;
1036#endif
1037
1038 /*
1039 * I wonder...
1040 * Will nasl_exec be really called with NODE_EXEC or NODE_ARG?
1041 */
1042 case NODE_DECL: /* Used in function declarations */
1043 /* [0] = next arg in list */
1044 /* TBD? */
1045 return st; /* ? */
1046
1047 case NODE_ARG: /* Used function calls */
1048 /* val = name can be NULL, [0] = val, [1] = next arg */
1049 ret = nasl_exec (lexic, st->link[0]); /* Is this wise? */
1050 return ret;
1051
1052 case NODE_RETURN:
1053 /* [0] = ret val */
1054 ret = nasl_return (lexic, st->link[0]);
1055 return ret;
1056
1057 case NODE_BREAK:
1058 lexic->break_flag = 1;
1059 return FAKE_CELL;
1060
1061 case NODE_CONTINUE:
1062 lexic->cont_flag = 1;
1063 return FAKE_CELL;
1064
1065 case NODE_ARRAY_EL: /* val = array name, [0] = index */
1066 idx = cell2atom (lexic, st->link[0]);
1067 ret = get_array_elem (lexic, st->x.str_val, idx);
1068 deref_cell (idx);
1069 return ret;
1070
1073 case NODE_AFF:
1074 /* [0] = lvalue, [1] = rvalue */
1075 tc1 = nasl_exec (lexic, st->link[0]);
1076 tc2 = nasl_exec (lexic, st->link[1]);
1077 ret = nasl_affect (tc1, tc2);
1078 deref_cell (tc1); /* Must free VAR_REF */
1079 deref_cell (ret);
1080 return tc2; /* So that "a = b = e;" works */
1081
1082 case NODE_PLUS_EQ:
1083 tc1 = nasl_exec (lexic, st->link[0]);
1084 tc2 = nasl_exec (lexic, st->link[1]);
1085 tc3 = alloc_expr_cell (0, EXPR_PLUS, tc1, tc2);
1086 ret2 = nasl_exec (lexic, tc3);
1087 ret = nasl_affect (tc1, ret2);
1088 deref_cell (tc3); /* Frees tc1 and tc2 */
1089 deref_cell (ret);
1090 return ret2; /* So that "a = b += e;" works */
1091
1092 case NODE_MINUS_EQ:
1093 tc1 = nasl_exec (lexic, st->link[0]);
1094 tc2 = nasl_exec (lexic, st->link[1]);
1095 tc3 = alloc_expr_cell (0, EXPR_MINUS, tc1, tc2);
1096 ret2 = nasl_exec (lexic, tc3);
1097 ret = nasl_affect (tc1, ret2);
1098 deref_cell (tc3); /* Frees tc1 and tc2 */
1099 deref_cell (ret);
1100 return ret2; /* So that "a = b -= e;" works */
1101
1102 case NODE_MULT_EQ:
1103 tc1 = nasl_exec (lexic, st->link[0]);
1104 tc2 = nasl_exec (lexic, st->link[1]);
1105 tc3 = alloc_expr_cell (0, EXPR_MULT, tc1, tc2);
1106 ret2 = nasl_exec (lexic, tc3);
1107 ret = nasl_affect (tc1, ret2);
1108 deref_cell (tc3); /* Frees tc1 and tc2 */
1109 deref_cell (ret);
1110 return ret2;
1111
1112 case NODE_DIV_EQ:
1113 tc1 = nasl_exec (lexic, st->link[0]);
1114 tc2 = nasl_exec (lexic, st->link[1]);
1115 tc3 = alloc_expr_cell (0, EXPR_DIV, tc1, tc2);
1116 ret2 = nasl_exec (lexic, tc3);
1117 ret = nasl_affect (tc1, ret2);
1118 deref_cell (tc3); /* Frees tc1 and tc2 */
1119 deref_cell (ret);
1120 return ret2;
1121
1122 case NODE_MODULO_EQ:
1123 tc1 = nasl_exec (lexic, st->link[0]);
1124 tc2 = nasl_exec (lexic, st->link[1]);
1125 tc3 = alloc_expr_cell (0, EXPR_MODULO, tc1, tc2);
1126 ret2 = nasl_exec (lexic, tc3);
1127 ret = nasl_affect (tc1, ret2);
1128 deref_cell (tc3); /* Frees tc1 and tc2 */
1129 deref_cell (ret);
1130 return ret2;
1131
1132 case NODE_L_SHIFT_EQ:
1133 tc1 = nasl_exec (lexic, st->link[0]);
1134 tc2 = nasl_exec (lexic, st->link[1]);
1135 tc3 = alloc_expr_cell (0, EXPR_L_SHIFT, tc1, tc2);
1136 ret2 = nasl_exec (lexic, tc3);
1137 ret = nasl_affect (tc1, ret2);
1138 deref_cell (tc3); /* Frees tc1 and tc2 */
1139 deref_cell (ret);
1140 return ret2;
1141
1142 case NODE_R_SHIFT_EQ:
1143 tc1 = nasl_exec (lexic, st->link[0]);
1144 tc2 = nasl_exec (lexic, st->link[1]);
1145 tc3 = alloc_expr_cell (0, EXPR_R_SHIFT, tc1, tc2);
1146 ret2 = nasl_exec (lexic, tc3);
1147 ret = nasl_affect (tc1, ret2);
1148 deref_cell (tc3); /* Frees tc1 and tc2 */
1149 deref_cell (ret);
1150 return ret2;
1151
1152 case NODE_R_USHIFT_EQ:
1153 tc1 = nasl_exec (lexic, st->link[0]);
1154 tc2 = nasl_exec (lexic, st->link[1]);
1155 tc3 = alloc_expr_cell (0, EXPR_R_USHIFT, tc1, tc2);
1156 ret2 = nasl_exec (lexic, tc3);
1157 ret = nasl_affect (tc1, ret2);
1158 deref_cell (tc3); /* Frees tc1 and tc2 */
1159 deref_cell (ret);
1160 return ret2;
1161
1162 case NODE_VAR:
1163 /* val = variable name */
1164 ret = get_variable_by_name (lexic, st->x.str_val);
1165 return ret;
1166
1167 case NODE_LOCAL: /* [0] = argdecl */
1168 ret = decl_local_variables (lexic, st->link[0]);
1169 return ret;
1170
1171 case NODE_GLOBAL: /* [0] = argdecl */
1172 ret = decl_global_variables (lexic, st->link[0]);
1173 return ret;
1174
1175 case EXPR_AND:
1176 x = cell2bool (lexic, st->link[0]);
1177 if (!x)
1178 return bool2cell (0);
1179
1180 y = cell2bool (lexic, st->link[1]);
1181 return bool2cell (y);
1182
1183 case EXPR_OR:
1184 x = cell2bool (lexic, st->link[0]);
1185 if (x)
1186 return bool2cell (x);
1187 y = cell2bool (lexic, st->link[1]);
1188 return bool2cell (y);
1189
1190 case EXPR_NOT:
1191 x = cell2bool (lexic, st->link[0]);
1192 return bool2cell (!x);
1193
1194 case EXPR_INCR:
1195 case EXPR_DECR:
1196 x = (st->type == EXPR_INCR) ? 1 : -1;
1197 if (st->link[0] == NULL)
1198 {
1199 y = 1; /* pre */
1200 tc1 = st->link[1];
1201 }
1202 else
1203 {
1204 y = 0; /* post */
1205 tc1 = st->link[0];
1206 }
1207 tc2 = nasl_exec (lexic, tc1);
1208 if (tc2 == NULL)
1209 return NULL;
1210 ret = nasl_incr_variable (lexic, tc2, y, x);
1211 deref_cell (tc2);
1212 return ret;
1213
1214 case EXPR_PLUS:
1215 s1 = s2 = NULL;
1216 tc1 = cell2atom (lexic, st->link[0]);
1217#ifdef STOP_AT_FIRST_ERROR
1218 if (tc1 == NULL || tc1 == FAKE_CELL)
1219 return NULL;
1220#endif
1221 tc2 = cell2atom (lexic, st->link[1]);
1222 if (tc2 == NULL || tc2 == FAKE_CELL)
1223 {
1224#ifdef STOP_AT_FIRST_ERROR
1225 deref_cell (tc1);
1226 return NULL;
1227#else
1228 return tc1;
1229#endif
1230 }
1231
1232 if (tc1 == NULL || tc1 == FAKE_CELL)
1233 return tc2;
1234
1235 /*
1236 * Anything added to a string is converted to a string
1237 * Otherwise anything added to an integer is converted into an integer
1238 */
1239 if (tc1->type == CONST_DATA || tc2->type == CONST_DATA)
1240 flag = CONST_DATA;
1241 else if (tc1->type == CONST_STR || tc2->type == CONST_STR)
1242 flag = CONST_STR;
1243 else if (tc1->type == CONST_INT || tc2->type == CONST_INT)
1244 flag = CONST_INT;
1245 else
1246 flag = NODE_EMPTY;
1247 switch (flag)
1248 {
1249 long sz;
1250 case CONST_INT:
1251 x = tc1->x.i_val;
1252 y = cell2int (lexic, tc2);
1253 ret = int2cell (x + y);
1254 break;
1255
1256 case CONST_STR:
1257 case CONST_DATA:
1258 s1 = s2 = NULL;
1259 if (tc1->type == CONST_STR || tc1->type == CONST_DATA)
1260 len1 = tc1->size;
1261 else
1262 {
1263 s1 = cell2str (lexic, tc1);
1264 len1 = (s1 == NULL ? 0 : strlen (s1));
1265 }
1266
1267 if (tc2->type == CONST_STR || tc2->type == CONST_DATA)
1268 len2 = tc2->size;
1269 else
1270 {
1271 s2 = cell2str (lexic, tc2);
1272 len2 = (s2 == NULL ? 0 : strlen (s2));
1273 }
1274
1275 sz = len1 + len2;
1276 s3 = g_malloc0 (sz + 1);
1277 if (len1 > 0)
1278 memcpy (s3, s1 != NULL ? s1 : tc1->x.str_val, len1);
1279 if (len2 > 0)
1280 memcpy (s3 + len1, s2 != NULL ? s2 : tc2->x.str_val, len2);
1281 g_free (s1);
1282 g_free (s2);
1283 ret = alloc_typed_cell (flag);
1284 ret->x.str_val = s3;
1285 ret->size = sz;
1286 break;
1287
1288 default:
1289 ret = NULL;
1290 break;
1291 }
1292 deref_cell (tc1);
1293 deref_cell (tc2);
1294 return ret;
1295
1296 case EXPR_MINUS: /* Infamous duplicated code */
1297 s1 = s2 = NULL;
1298 tc1 = cell2atom (lexic, st->link[0]);
1299#ifdef STOP_AT_FIRST_ERROR
1300 if (tc1 == NULL || tc1 == FAKE_CELL)
1301 return NULL;
1302#endif
1303 tc2 = cell2atom (lexic, st->link[1]);
1304 if (tc2 == NULL || tc2 == FAKE_CELL)
1305 {
1306#ifdef STOP_AT_FIRST_ERROR
1307 deref_cell (tc1);
1308 return NULL;
1309#else
1310 return tc1;
1311#endif
1312 }
1313
1314 if (tc1 == NULL || tc1 == FAKE_CELL)
1315 {
1316 if (tc2->type == CONST_INT)
1317 {
1318 y = cell2int (lexic, tc2);
1319 ret = int2cell (-y);
1320 }
1321 else
1322 ret = NULL;
1323 deref_cell (tc2);
1324 return ret;
1325 }
1326
1327 /*
1328 * Anything subtracted from a string is converted to a string
1329 * Otherwise anything subtracted from integer is converted into an
1330 * integer
1331 */
1332 if (tc1->type == CONST_DATA || tc2->type == CONST_DATA)
1333 flag = CONST_DATA;
1334 else if (tc1->type == CONST_STR || tc2->type == CONST_STR)
1335 flag = CONST_STR;
1336 else if (tc1->type == CONST_INT || tc2->type == CONST_INT)
1337 flag = CONST_INT;
1338 else
1339 flag = NODE_EMPTY;
1340 switch (flag)
1341 {
1342 case CONST_INT:
1343 x = cell2int (lexic, tc1);
1344 y = cell2int (lexic, tc2);
1345 ret = int2cell (x - y);
1346 break;
1347
1348 case CONST_STR:
1349 case CONST_DATA:
1350 if (tc1->type == CONST_STR || tc1->type == CONST_DATA)
1351 {
1352 p1 = tc1->x.str_val;
1353 len1 = tc1->size;
1354 }
1355 else
1356 {
1357 p1 = s1 = cell2str (lexic, tc1);
1358 len1 = (s1 == NULL ? 0 : strlen (s1));
1359 }
1360
1361 if (tc2->type == CONST_STR || tc2->type == CONST_DATA)
1362 {
1363 p2 = tc2->x.str_val;
1364 len2 = tc2->size;
1365 }
1366 else
1367 {
1368 p2 = s2 = cell2str (lexic, tc2);
1369 len2 = (s2 == NULL ? 0 : strlen (s2));
1370 }
1371
1372 /* if p1 is null, last condition p=memem() will not be evaluated
1373 * and p remains NULL */
1374 if (len2 == 0 || len1 < len2
1375 || (p1 != NULL && (p = memmem (p1, len1, p2, len2)) == NULL))
1376 {
1377 s3 = g_malloc0 (len1 + 1);
1378 if (p1 != NULL)
1379 memcpy (s3, p1, len1);
1380 ret = alloc_typed_cell (flag);
1381 ret->x.str_val = s3;
1382 ret->size = len1;
1383 }
1384 else
1385 {
1386 long sz = len1 - len2;
1387 if (sz <= 0)
1388 {
1389 sz = 0;
1390 s3 = g_strdup ("");
1391 }
1392 else
1393 {
1394 s3 = g_malloc0 (sz + 1);
1395 if (p - p1 > 0)
1396 memcpy (s3, p1, p - p1);
1397 if (p != NULL && sz > p - p1)
1398 memcpy (s3 + (p - p1), p + len2, sz - (p - p1));
1399 }
1400 ret = alloc_typed_cell (flag);
1401 ret->x.str_val = s3;
1402 ret->size = sz;
1403 }
1404
1405 g_free (s1);
1406 g_free (s2);
1407 break;
1408
1409 default:
1410 ret = NULL;
1411 break;
1412 }
1413 deref_cell (tc1);
1414 deref_cell (tc2);
1415 return ret;
1416
1417 case EXPR_MULT:
1418 x = cell2intW (lexic, st->link[0]);
1419 y = cell2intW (lexic, st->link[1]);
1420 return int2cell (x * y);
1421
1422 case EXPR_DIV:
1423 x = cell2intW (lexic, st->link[0]);
1424 y = cell2intW (lexic, st->link[1]);
1425 if (y != 0)
1426 return int2cell (x / y);
1427 else
1428 return int2cell (0);
1429
1430 case EXPR_EXPO:
1431 x = cell2intW (lexic, st->link[0]);
1432 y = cell2intW (lexic, st->link[1]);
1433 return int2cell (expo (x, y));
1434
1435 case EXPR_MODULO:
1436 x = cell2intW (lexic, st->link[0]);
1437 y = cell2intW (lexic, st->link[1]);
1438 if (y != 0)
1439 return int2cell (x % y);
1440 else
1441 return int2cell (0);
1442
1443 case EXPR_BIT_AND:
1444 x = cell2intW (lexic, st->link[0]);
1445 y = cell2intW (lexic, st->link[1]);
1446 return int2cell (x & y);
1447
1448 case EXPR_BIT_OR:
1449 x = cell2intW (lexic, st->link[0]);
1450 y = cell2intW (lexic, st->link[1]);
1451 return int2cell (x | y);
1452
1453 case EXPR_BIT_XOR:
1454 x = cell2intW (lexic, st->link[0]);
1455 y = cell2intW (lexic, st->link[1]);
1456 return int2cell (x ^ y);
1457
1458 case EXPR_BIT_NOT:
1459 x = cell2intW (lexic, st->link[0]);
1460 return int2cell (~x);
1461
1462 case EXPR_U_MINUS:
1463 x = cell2intW (lexic, st->link[0]);
1464 return int2cell (-x);
1465
1466 /* TBD: Handle shift for strings and arrays */
1467 case EXPR_L_SHIFT:
1468 x = cell2intW (lexic, st->link[0]);
1469 y = cell2intW (lexic, st->link[1]);
1470 return int2cell (x << y);
1471
1472 case EXPR_R_SHIFT: /* arithmetic right shift */
1473 x = cell2intW (lexic, st->link[0]);
1474 y = cell2intW (lexic, st->link[1]);
1475 z = x >> y;
1476#ifndef __GNUC__
1477 if (x < 0 && z >= 0) /* Fix it */
1478 z |= (~0) << (sizeof (x) * 8 - y);
1479#endif
1480 return int2cell (z);
1481
1482 case EXPR_R_USHIFT:
1483 x = cell2intW (lexic, st->link[0]);
1484 y = cell2intW (lexic, st->link[1]);
1485 z = (unsigned) x >> (unsigned) y;
1486#ifndef __GNUC__
1487 if (x < 0 && z <= 0) /* Fix it! */
1488 z &= ~((~0) << (sizeof (x) * 8 - y));
1489#endif
1490 return int2cell (z);
1491
1492 case COMP_MATCH:
1493 case COMP_NOMATCH:
1494 tc1 = cell2atom (lexic, st->link[0]);
1495 tc2 = cell2atom (lexic, st->link[1]);
1496 s1 = s2 = NULL;
1497
1498 if (tc1 == NULL || tc1 == FAKE_CELL)
1499 {
1500 p1 = "";
1501 len1 = 0;
1502 }
1503 else if (tc1->type == CONST_STR || tc1->type == CONST_DATA)
1504 {
1505 p1 = tc1->x.str_val;
1506 len1 = tc1->size;
1507 }
1508 else
1509 {
1510 p1 = s1 = cell2str (lexic, tc1);
1511 len1 = strlen (s1);
1512 }
1513
1514 if (tc2 == NULL || tc2 == FAKE_CELL)
1515 {
1516 p2 = "";
1517 len2 = 0;
1518 }
1519 else if (tc2->type == CONST_STR || tc2->type == CONST_DATA)
1520 {
1521 p2 = tc2->x.str_val;
1522 len2 = tc2->size;
1523 }
1524 else
1525 {
1526 p2 = s2 = cell2str (lexic, tc2);
1527 len2 = strlen (s2);
1528 }
1529
1530 if (len1 <= len2)
1531 flag = (memmem (p2, len2, p1, len1) != NULL);
1532 else
1533 flag = 0;
1534
1535 g_free (s1);
1536 g_free (s2);
1537 deref_cell (tc1);
1538 deref_cell (tc2);
1539 if (st->type == COMP_MATCH)
1540 return bool2cell (flag);
1541 else
1542 return bool2cell (!flag);
1543
1544 case COMP_RE_MATCH:
1545 case COMP_RE_NOMATCH:
1546 if (st->x.ref_val == NULL)
1547 {
1548 nasl_perror (lexic, "nasl_exec: bad regex at or near line %d\n",
1549 st->line_nb);
1550 return NULL;
1551 }
1552 s1 = cell2str (lexic, st->link[0]);
1553 if (s1 == NULL)
1554 return 0;
1555 flag = regexec (st->x.ref_val, s1, 0, NULL, 0);
1556 g_free (s1);
1557 if (st->type == COMP_RE_MATCH)
1558 return bool2cell (flag != REG_NOMATCH);
1559 else
1560 return bool2cell (flag == REG_NOMATCH);
1561
1562 case COMP_LT:
1563 return bool2cell (cell_cmp (lexic, st->link[0], st->link[1]) < 0);
1564
1565 case COMP_LE:
1566 return bool2cell (cell_cmp (lexic, st->link[0], st->link[1]) <= 0);
1567
1568 case COMP_EQ:
1569 return bool2cell (cell_cmp (lexic, st->link[0], st->link[1]) == 0);
1570
1571 case COMP_NE:
1572 return bool2cell (cell_cmp (lexic, st->link[0], st->link[1]) != 0);
1573
1574 case COMP_GT:
1575 return bool2cell (cell_cmp (lexic, st->link[0], st->link[1]) > 0);
1576
1577 case COMP_GE:
1578 return bool2cell (cell_cmp (lexic, st->link[0], st->link[1]) >= 0);
1579
1580 case REF_ARRAY:
1581 case DYN_ARRAY:
1582 case CONST_INT:
1583 case CONST_STR:
1584 case CONST_DATA:
1585 ref_cell (st); /* nasl_exec returns a cell that should be deref-ed */
1586 return st;
1587
1588 case REF_VAR:
1589 ret = nasl_read_var_ref (lexic, st);
1590 return ret;
1591
1592 default:
1593 nasl_perror (lexic, "nasl_exec: unhandled node type %d\n", st->type);
1594 abort ();
1595 return NULL;
1596 }
1597}
FILE * nasl_trace_fp
Definition exec.c:358
long int cell_cmp(lex_ctxt *lexic, tree_cell *c1, tree_cell *c2)
Definition exec.c:219
static long int cell2intW(lex_ctxt *lexic, tree_cell *c)
Definition exec.c:131
static void nasl_short_dump(FILE *fp, const tree_cell *c)
Definition exec.c:652
static tree_cell * bool2cell(long int x)
Definition exec.c:145
tree_cell * decl_nasl_func(lex_ctxt *lexic, tree_cell *decl_node, int lint_mode)
Definition nasl_func.c:66
tree_cell * nasl_return(lex_ctxt *ctxt, tree_cell *retv)
Definition nasl_func.c:236
const char * val
Definition nasl_init.c:441
tree_cell * nasl_incr_variable(lex_ctxt *, tree_cell *, int, int)
Definition nasl_var.c:919
tree_cell * get_array_elem(lex_ctxt *, const char *, tree_cell *)
Definition nasl_var.c:208
tree_cell * nasl_read_var_ref(lex_ctxt *, tree_cell *)
Definition nasl_var.c:832
tree_cell * decl_global_variables(lex_ctxt *, tree_cell *)
Definition nasl_var.c:771
tree_cell * decl_local_variables(lex_ctxt *, tree_cell *)
Definition nasl_var.c:758
tree_cell * get_variable_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:176
tree_cell * alloc_typed_cell(int typ)
Definition nasl_tree.c:25
@ NODE_FOR
Definition nasl_tree.h:16
@ NODE_LOCAL
Definition nasl_tree.h:32
@ COMP_NE
Definition nasl_tree.h:75
@ NODE_ARG
Definition nasl_tree.h:24
@ NODE_CONTINUE
Definition nasl_tree.h:27
@ NODE_FUN_DEF
Definition nasl_tree.h:21
@ NODE_REPEAT_UNTIL
Definition nasl_tree.h:19
@ NODE_REPEATED
Definition nasl_tree.h:20
@ NODE_RETURN
Definition nasl_tree.h:25
@ NODE_EMPTY
Definition nasl_tree.h:13
@ NODE_FOREACH
Definition nasl_tree.h:18
@ NODE_IF_ELSE
Definition nasl_tree.h:14
@ NODE_DECL
Definition nasl_tree.h:23
@ NODE_INSTR_L
Definition nasl_tree.h:15
@ NODE_BREAK
Definition nasl_tree.h:26
@ NODE_GLOBAL
Definition nasl_tree.h:33
@ NODE_WHILE
Definition nasl_tree.h:17
nasl_iterator nasl_array_iterator(void *ctxt, tree_cell *c)
Definition nasl_var.c:1169
tree_cell * nasl_iterate_array(nasl_iterator *it)
Definition nasl_var.c:1205
tree_cell * nasl_affect(tree_cell *lval, tree_cell *rval)
Definition nasl_var.c:697
void free_array(nasl_array *a)
Definition nasl_var.c:339
short line_nb
Definition nasl_tree.h:96
nasl_array * a
Definition nasl_var.h:67
tree_cell * ret_val
unsigned break_flag

References nasl_iterator::a, alloc_expr_cell(), alloc_typed_cell(), bool2cell(), struct_lex_ctxt::break_flag, cell2atom(), cell2bool(), cell2int(), cell2intW(), cell2str(), cell_cmp(), COMP_EQ, COMP_GE, COMP_GT, COMP_LE, COMP_LT, COMP_MATCH, COMP_NE, COMP_NOMATCH, COMP_RE_MATCH, COMP_RE_NOMATCH, CONST_DATA, CONST_INT, CONST_STR, struct_lex_ctxt::cont_flag, decl_global_variables(), decl_local_variables(), decl_nasl_func(), deref_cell(), DYN_ARRAY, expo(), EXPR_AND, EXPR_BIT_AND, EXPR_BIT_NOT, EXPR_BIT_OR, EXPR_BIT_XOR, EXPR_DECR, EXPR_DIV, EXPR_EXPO, EXPR_INCR, EXPR_L_SHIFT, EXPR_MINUS, EXPR_MODULO, EXPR_MULT, EXPR_NOT, EXPR_OR, EXPR_PLUS, EXPR_R_SHIFT, EXPR_R_USHIFT, EXPR_U_MINUS, FAKE_CELL, free_array(), get_array_elem(), get_func_ref_by_name(), get_variable_by_name(), int2cell(), struct_lex_ctxt::line_nb, TC::line_nb, TC::link, nasl_affect(), nasl_array_iterator(), nasl_exec(), nasl_func_call(), nasl_incr_variable(), nasl_iterate_array(), nasl_perror(), nasl_read_var_ref(), nasl_return(), nasl_short_dump(), nasl_trace_fp, NODE_AFF, NODE_ARG, NODE_ARRAY_EL, NODE_BREAK, NODE_CONTINUE, NODE_DECL, NODE_DIV_EQ, NODE_EMPTY, NODE_FOR, NODE_FOREACH, NODE_FUN_CALL, NODE_FUN_DEF, NODE_GLOBAL, NODE_IF_ELSE, NODE_INSTR_L, NODE_L_SHIFT_EQ, NODE_LOCAL, NODE_MINUS_EQ, NODE_MODULO_EQ, NODE_MULT_EQ, NODE_PLUS_EQ, NODE_R_SHIFT_EQ, NODE_R_USHIFT_EQ, NODE_REPEAT_UNTIL, NODE_REPEATED, NODE_RETURN, NODE_VAR, NODE_WHILE, REF_ARRAY, ref_cell(), TC::ref_val, REF_VAR, struct_lex_ctxt::ret_val, TC::size, TC::str_val, TC::type, val, and TC::x.

Referenced by cell2atom(), cell2bool(), cell2int3(), cell2str(), exec_nasl_script(), nasl_exec(), and nasl_func_call().

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

◆ nasl_short_dump()

void nasl_short_dump ( FILE * fp,
const tree_cell * c )
static

Definition at line 652 of file exec.c.

653{
654 if (c == NULL || c == FAKE_CELL)
655 return;
656
657 switch (c->type)
658 {
659 case NODE_IF_ELSE:
660 fprintf (fp, "NASL:%04d> if (", c->line_nb);
661 nasl_dump_expr (fp, c->link[0]);
662 fprintf (fp, ") { ... }");
663 if (c->link[2] != NULL)
664 fprintf (fp, " else { ... }");
665 putc ('\n', fp);
666 break;
667
668 case NODE_FOR:
669 fprintf (fp, "NASL:%04d> for (", c->line_nb);
670 nasl_dump_expr (fp, c->link[0]);
671 fprintf (fp, "; ");
672 nasl_dump_expr (fp, c->link[1]);
673 fprintf (fp, "; ");
674 nasl_dump_expr (fp, c->link[2]);
675 fprintf (fp, ") { ... }\n");
676 break;
677
678 case NODE_WHILE:
679 fprintf (fp, "NASL:%04d> while (", c->line_nb);
680 nasl_dump_expr (fp, c->link[0]);
681 fprintf (fp, ") { ... }\n");
682 break;
683
684 case NODE_FOREACH:
685 fprintf (fp, "NASL:%04d> foreach %s (", c->line_nb, c->x.str_val);
686 nasl_dump_expr (fp, c->link[0]);
687 fprintf (fp, ") { ... }\n");
688 break;
689
691 fprintf (fp, "NASL:%04d> repeat { ... } until (", c->line_nb);
692 nasl_dump_expr (fp, c->link[0]);
693 fprintf (fp, ")\n");
694 break;
695
696 case NODE_REPEATED:
697 fprintf (fp, "NASL:%04d> ... x ", c->line_nb);
698 nasl_dump_expr (fp, c->link[1]);
699 putc ('\n', fp);
700 break;
701
702 case NODE_RETURN:
703 fprintf (fp, "NASL:%04d> return ", c->line_nb);
704 nasl_dump_expr (fp, c->link[0]);
705 fprintf (fp, ";\n");
706 break;
707
708 case NODE_BREAK:
709 fprintf (fp, "NASL:%04d> break\n", c->line_nb);
710 break;
711
712 case NODE_CONTINUE:
713 fprintf (fp, "NASL:%04d> continue\n", c->line_nb);
714 break;
715
716 case NODE_AFF:
717 case NODE_PLUS_EQ:
718 case NODE_MINUS_EQ:
719 case NODE_MULT_EQ:
720 case NODE_DIV_EQ:
721 case NODE_MODULO_EQ:
722 case NODE_R_SHIFT_EQ:
723 case NODE_R_USHIFT_EQ:
724 case NODE_L_SHIFT_EQ:
725 fprintf (fp, "NASL:%04d> ", c->line_nb);
726 nasl_dump_expr (fp, c);
727 fprintf (fp, ";\n");
728 break;
729
730 case NODE_FUN_CALL:
731 fprintf (fp, "NASL:%04d> %s(...)\n", c->line_nb, c->x.str_val);
732 break;
733
734 case NODE_LOCAL:
735 fprintf (fp, "NASL:%04d> local_var ...\n", c->line_nb);
736 break;
737
738 case NODE_GLOBAL:
739 fprintf (fp, "NASL:%04d> global_var ...\n", c->line_nb);
740 break;
741 }
742}

References FAKE_CELL, TC::line_nb, TC::link, nasl_dump_expr(), NODE_AFF, NODE_BREAK, NODE_CONTINUE, NODE_DIV_EQ, NODE_FOR, NODE_FOREACH, NODE_FUN_CALL, NODE_GLOBAL, NODE_IF_ELSE, NODE_L_SHIFT_EQ, NODE_LOCAL, NODE_MINUS_EQ, NODE_MODULO_EQ, NODE_MULT_EQ, NODE_PLUS_EQ, NODE_R_SHIFT_EQ, NODE_R_USHIFT_EQ, NODE_REPEAT_UNTIL, NODE_REPEATED, NODE_RETURN, NODE_WHILE, TC::str_val, 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:

◆ naslparse()

int naslparse ( naslctxt * ,
int *  )
extern

Referenced by exec_nasl_script(), and yyparse().

Here is the caller graph for this function:

Variable Documentation

◆ nasl_trace_fp

FILE* nasl_trace_fp = NULL

◆ truc

lex_ctxt* truc = NULL

Definition at line 360 of file exec.c.

Referenced by exec_nasl_script().