24 #include "../misc/plugutils.h" 35 #include <glib/gstdio.h> 36 #include <gvm/base/logging.h> 37 #include <gvm/base/prefs.h> 38 #include <gvm/util/nvticache.h> 49 #define G_LOG_DOMAIN "lib nasl" 104 if (*p !=
'\0' && warn)
109 "Converting the non numeric string '%s' in variable " 110 "'%s' to integer does not make sense in this " 116 "Converting the non numeric string '%s' to " 117 "integer does not make sense in this context",
173 return g_strdup_printf (
"%ld", c->
x.
i_val);
181 p = g_malloc0 (c->
size + 1);
231 int flag, typ, typ1, typ2;
234 int len_s1, len_s2, len_min;
260 if (typ1 == 0 && typ2 == 0)
301 "cell_cmp: comparing '%s' of type %s and '%s' of " 302 "type %s does not make sense\n",
328 len_s1 = strlen (s1);
336 len_s2 = strlen (s2);
338 len_min = len_s1 < len_s2 ? len_s1 : len_s2;
342 flag = memcmp (s1, s2, len_min);
344 flag = len_s1 - len_s2;
354 g_message (
"cell_cmp: cannot compare arrays yet");
360 g_message (
"cell_cmp: don't known how to compare %s and %s",
376 fprintf (fp,
"NULL");
378 fprintf (fp,
"FAKE");
388 fprintf (fp,
") && (");
395 fprintf (fp,
") || (");
407 fprintf (fp,
") + (");
414 fprintf (fp,
") - (");
420 if (c->
link[0] == NULL)
432 if (c->
link[0] == NULL)
448 fprintf (fp,
") ** (");
454 fprintf (fp,
" - (");
462 fprintf (fp,
") * (");
469 fprintf (fp,
") / (");
476 fprintf (fp,
") %% (");
483 fprintf (fp,
") & (");
490 fprintf (fp,
") | (");
497 fprintf (fp,
") ^ (");
509 fprintf (fp,
") << (");
516 fprintf (fp,
") >> (");
523 fprintf (fp,
") >>> (");
529 fprintf (fp,
" >< ");
534 fprintf (fp,
" >!< ");
540 fprintf (fp,
" =~ ");
546 fprintf (fp,
" !~ ");
557 fprintf (fp,
" <= ");
567 fprintf (fp,
" >= ");
572 fprintf (fp,
" == ");
576 fprintf (fp,
"%ld", c->
x.
i_val);
580 fprintf (fp,
"\"%s\"", c->
x.
str_val);
590 fprintf (fp,
"%s(...)", c->
x.
str_val);
601 fprintf (fp,
"+= (");
608 fprintf (fp,
"-= (");
615 fprintf (fp,
"*= (");
622 fprintf (fp,
"/= (");
629 fprintf (fp,
"%%= (");
636 fprintf (fp,
" <<= (");
643 fprintf (fp,
" >>= (");
650 fprintf (fp,
" >>>= (");
656 fprintf (fp,
"*%d*", c->
type);
670 fprintf (fp,
"NASL:%04d> if (", c->
line_nb);
672 fprintf (fp,
") { ... }");
673 if (c->
link[2] != NULL)
674 fprintf (fp,
" else { ... }");
679 fprintf (fp,
"NASL:%04d> for (", c->
line_nb);
685 fprintf (fp,
") { ... }\n");
689 fprintf (fp,
"NASL:%04d> while (", c->
line_nb);
691 fprintf (fp,
") { ... }\n");
697 fprintf (fp,
") { ... }\n");
701 fprintf (fp,
"NASL:%04d> repeat { ... } until (", c->
line_nb);
707 fprintf (fp,
"NASL:%04d> ... x ", c->
line_nb);
713 fprintf (fp,
"NASL:%04d> return ", c->
line_nb);
719 fprintf (fp,
"NASL:%04d> break\n", c->
line_nb);
723 fprintf (fp,
"NASL:%04d> continue\n", c->
line_nb);
735 fprintf (fp,
"NASL:%04d> ", c->
line_nb);
745 fprintf (fp,
"NASL:%04d> local_var ...\n", c->
line_nb);
749 fprintf (fp,
"NASL:%04d> global_var ...\n", c->
line_nb);
783 tree_cell *ret = NULL, *ret2 = NULL, *tc1 = NULL, *tc2 = NULL, *tc3 = NULL,
786 char *s1 = NULL, *s2 = NULL, *s3 = NULL, *p = NULL;
791 int i, lint_mode = 0;
822 #ifdef STOP_AT_FIRST_ERROR 828 else if (st->
link[2] != NULL)
846 #ifdef STOP_AT_FIRST_ERROR 869 #ifdef STOP_AT_FIRST_ERROR 886 #ifdef STOP_AT_FIRST_ERROR 913 #ifdef STOP_AT_FIRST_ERROR 941 #ifdef STOP_AT_FIRST_ERROR 957 #ifdef STOP_AT_FIRST_ERROR 985 #ifdef STOP_AT_FIRST_ERROR 1031 #ifdef STOP_AT_FIRST_ERROR 1032 for (tc1 = NULL, i = 1; i <= n; i++)
1040 for (i = 1; i <= n; i++)
1207 if (st->
link[0] == NULL)
1227 #ifdef STOP_AT_FIRST_ERROR 1234 #ifdef STOP_AT_FIRST_ERROR 1274 len1 = (s1 == NULL ? 0 : strlen (s1));
1282 len2 = (s2 == NULL ? 0 : strlen (s2));
1286 s3 = g_malloc0 (sz + 1);
1288 memcpy (s3, s1 != NULL ? s1 : tc1->x.str_val, len1);
1290 memcpy (s3 + len1, s2 != NULL ? s2 : tc2->x.str_val, len2);
1309 #ifdef STOP_AT_FIRST_ERROR 1316 #ifdef STOP_AT_FIRST_ERROR 1362 p1 = tc1->x.str_val;
1368 len1 = (s1 == NULL ? 0 : strlen (s1));
1373 p2 = tc2->x.str_val;
1379 len2 = (s2 == NULL ? 0 : strlen (s2));
1382 if (len2 == 0 || len1 < len2
1383 || (p = memmem (p1, len1, p2, len2)) == NULL)
1385 s3 = g_malloc0 (len1 + 1);
1386 memcpy (s3, p1, len1);
1393 long sz = len1 - len2;
1401 s3 = g_malloc0 (sz + 1);
1403 memcpy (s3, p1, p - p1);
1405 memcpy (s3 + (p - p1), p + len2, sz - (p - p1));
1484 if (x < 0 && z >= 0)
1485 z |= (~0) << (
sizeof (x) * 8 - y);
1492 z = (unsigned) x >> (
unsigned) y;
1494 if (x < 0 && z <= 0)
1495 z &= ~((~0) << (
sizeof (x) * 8 - y));
1512 p1 = tc1->x.str_val;
1528 p2 = tc2->x.str_val;
1538 flag = (memmem (p2, len2, p1, len1) != NULL);
1555 nasl_perror (lexic,
"nasl_exec: bad regex at or near line %d\n",
1562 flag = regexec (st->
x.
ref_val, s1, 0, NULL, 0);
1628 int err = 0, to, process_id;
1635 gchar *short_name = g_path_get_basename (
name);
1638 g_free (short_name);
1640 srand48 (getpid () + getppid () + (
long) time (NULL));
1642 old_dir = g_get_current_dir ();
1644 newdir = g_path_get_dirname (
name);
1646 if (g_chdir (newdir) != 0)
1648 g_message (
"%s: Not able to open nor to locate it in include paths",
1656 bzero (&ctx,
sizeof (ctx));
1659 if (nvticache_initialized ())
1660 ctx.
kb = nvticache_get_kb ();
1668 g_message (
"%s: Parse error at or near line %d",
name, ctx.
line_nb);
1687 str = prefs_get (
"checks_read_timeout");
1698 process_id = getpid ();
1708 bzero (&tc,
sizeof (tc));
1713 bzero (&tc,
sizeof (tc));
1719 p = strrchr (
name,
'/');
1725 tc.
size = strlen (p);
1738 if (g_chdir (old_dir) != 0)
1747 if (process_id != getpid ())
tree_cell * nasl_return(lex_ctxt *ctxt, tree_cell *retv)
static long int expo(long int x, long int y)
int exec_nasl_script(struct script_infos *script_infos, int mode)
Execute a NASL script.
void ref_cell(tree_cell *c)
static long int cell2int(lex_ctxt *lexic, tree_cell *c)
static tree_cell * bool2cell(long int x)
static int cell2bool(lex_ctxt *lexic, tree_cell *c)
#define NASL_EXEC_PARSE_ONLY
void nasl_clean_ctx(naslctxt *)
tree_cell * cell2atom(lex_ctxt *lexic, tree_cell *c1)
void deref_cell(tree_cell *c)
kb_t plug_get_kb(struct script_infos *args)
void nasl_set_plugin_filename(const char *filename)
Set the current launched plugin filename.
void nasl_set_filename(const char *filename)
int init_nasl_ctx(naslctxt *, const char *)
Initialize a NASL context for a NASL file.
struct script_infos * script_infos
tree_cell * nasl_lint(lex_ctxt *, tree_cell *)
Search for errors in a nasl script.
void free_lex_ctxt(lex_ctxt *c)
static long int cell2int3(lex_ctxt *lexic, tree_cell *c, int warn, named_nasl_var *v)
tree_cell * alloc_typed_cell(int typ)
tree_cell * nasl_incr_variable(lex_ctxt *, tree_cell *, int, int)
static void nasl_short_dump(FILE *fp, const tree_cell *c)
#define NASL_COMMAND_LINE
tree_cell * decl_local_variables(lex_ctxt *, tree_cell *)
lex_ctxt * init_empty_lex_ctxt()
tree_cell * get_variable_by_name(lex_ctxt *, const char *)
named_nasl_var * add_named_var_to_ctxt(lex_ctxt *, const char *, tree_cell *)
static void nasl_dump_expr(FILE *fp, const tree_cell *c)
char * array2str(const nasl_array *a)
long int cell_cmp(lex_ctxt *lexic, tree_cell *c1, tree_cell *c2)
void nasl_perror(lex_ctxt *lexic, char *msg,...)
#define NASL_ALWAYS_SIGNED
static char * cell2str(lex_ctxt *lexic, tree_cell *c)
tree_cell * nasl_func_call(lex_ctxt *lexic, const nasl_func *f, tree_cell *arg_list)
tree_cell * get_array_elem(lex_ctxt *, const char *, tree_cell *)
int naslparse(naslctxt *)
nasl_iterator nasl_array_iterator(void *ctxt, tree_cell *c)
tree_cell * nasl_iterate_array(nasl_iterator *it)
const char * nasl_type_name(int t)
static tree_cell * int2cell(long int x)
tree_cell * nasl_read_var_ref(lex_ctxt *, tree_cell *)
int cell_type(const tree_cell *c)
void free_array(nasl_array *a)
tree_cell * alloc_expr_cell(int lnb, int t, tree_cell *l, tree_cell *r)
tree_cell * decl_global_variables(lex_ctxt *, tree_cell *)
tree_cell * nasl_affect(tree_cell *lval, tree_cell *rval)
tree_cell * decl_nasl_func(lex_ctxt *lexic, tree_cell *decl_node, int lint_mode)
nasl_func * get_func_ref_by_name(lex_ctxt *ctxt, const char *name)
tree_cell * nasl_exec(lex_ctxt *lexic, tree_cell *st)
Execute a parse tree.
static long int cell2intW(lex_ctxt *lexic, tree_cell *c)