25#include <glib/gstdio.h>
26#include <gvm/base/logging.h>
27#include <gvm/base/prefs.h>
28#include <gvm/util/nvticache.h>
39#define G_LOG_DOMAIN "lib nasl"
94 if (*p !=
'\0' && warn)
99 "Converting the non numeric string '%s' in variable "
100 "'%s' to integer does not make sense in this "
106 "Converting the non numeric string '%s' to "
107 "integer does not make sense in this context",
163 return g_strdup_printf (
"%ld", c->
x.
i_val);
171 p = g_malloc0 (c->
size + 1);
221 int flag, typ, typ1, typ2;
224 int len_s1, len_s2, len_min;
250 if (typ1 == 0 && typ2 == 0)
291 "cell_cmp: comparing '%s' of type %s and '%s' of "
292 "type %s does not make sense\n",
318 len_s1 = strlen (s1);
326 len_s2 = strlen (s2);
328 len_min = len_s1 < len_s2 ? len_s1 : len_s2;
332 flag = memcmp (s1, s2, len_min);
334 flag = len_s1 - len_s2;
344 g_message (
"cell_cmp: cannot compare arrays yet");
350 g_message (
"cell_cmp: don't known how to compare %s and %s",
366 fprintf (fp,
"NULL");
368 fprintf (fp,
"FAKE");
378 fprintf (fp,
") && (");
385 fprintf (fp,
") || (");
397 fprintf (fp,
") + (");
404 fprintf (fp,
") - (");
410 if (c->
link[0] == NULL)
422 if (c->
link[0] == NULL)
438 fprintf (fp,
") ** (");
444 fprintf (fp,
" - (");
452 fprintf (fp,
") * (");
459 fprintf (fp,
") / (");
466 fprintf (fp,
") %% (");
473 fprintf (fp,
") & (");
480 fprintf (fp,
") | (");
487 fprintf (fp,
") ^ (");
499 fprintf (fp,
") << (");
506 fprintf (fp,
") >> (");
513 fprintf (fp,
") >>> (");
519 fprintf (fp,
" >< ");
524 fprintf (fp,
" >!< ");
530 fprintf (fp,
" =~ ");
536 fprintf (fp,
" !~ ");
547 fprintf (fp,
" <= ");
557 fprintf (fp,
" >= ");
562 fprintf (fp,
" == ");
566 fprintf (fp,
"%ld", c->
x.
i_val);
570 fprintf (fp,
"\"%s\"", c->
x.
str_val);
580 fprintf (fp,
"%s(...)", c->
x.
str_val);
591 fprintf (fp,
"+= (");
598 fprintf (fp,
"-= (");
605 fprintf (fp,
"*= (");
612 fprintf (fp,
"/= (");
619 fprintf (fp,
"%%= (");
626 fprintf (fp,
" <<= (");
633 fprintf (fp,
" >>= (");
640 fprintf (fp,
" >>>= (");
646 fprintf (fp,
"*%d*", c->
type);
660 fprintf (fp,
"NASL:%04d> if (", c->
line_nb);
662 fprintf (fp,
") { ... }");
663 if (c->
link[2] != NULL)
664 fprintf (fp,
" else { ... }");
669 fprintf (fp,
"NASL:%04d> for (", c->
line_nb);
675 fprintf (fp,
") { ... }\n");
679 fprintf (fp,
"NASL:%04d> while (", c->
line_nb);
681 fprintf (fp,
") { ... }\n");
687 fprintf (fp,
") { ... }\n");
691 fprintf (fp,
"NASL:%04d> repeat { ... } until (", c->
line_nb);
697 fprintf (fp,
"NASL:%04d> ... x ", c->
line_nb);
703 fprintf (fp,
"NASL:%04d> return ", c->
line_nb);
709 fprintf (fp,
"NASL:%04d> break\n", c->
line_nb);
713 fprintf (fp,
"NASL:%04d> continue\n", c->
line_nb);
725 fprintf (fp,
"NASL:%04d> ", c->
line_nb);
735 fprintf (fp,
"NASL:%04d> local_var ...\n", c->
line_nb);
739 fprintf (fp,
"NASL:%04d> global_var ...\n", c->
line_nb);
773 tree_cell *ret = NULL, *ret2 = NULL, *tc1 = NULL, *tc2 = NULL, *tc3 = NULL,
776 char *s1 = NULL, *s2 = NULL, *s3 = NULL, *p = NULL;
781 int i, lint_mode = 0;
812#ifdef STOP_AT_FIRST_ERROR
818 else if (st->
link[2] != NULL)
836#ifdef STOP_AT_FIRST_ERROR
859#ifdef STOP_AT_FIRST_ERROR
876#ifdef STOP_AT_FIRST_ERROR
903#ifdef STOP_AT_FIRST_ERROR
931#ifdef STOP_AT_FIRST_ERROR
947#ifdef STOP_AT_FIRST_ERROR
975#ifdef STOP_AT_FIRST_ERROR
1021#ifdef STOP_AT_FIRST_ERROR
1022 for (tc1 = NULL, i = 1; i <= n; i++)
1030 for (i = 1; i <= n; i++)
1197 if (st->
link[0] == NULL)
1217#ifdef STOP_AT_FIRST_ERROR
1224#ifdef STOP_AT_FIRST_ERROR
1264 len1 = (s1 == NULL ? 0 : strlen (s1));
1272 len2 = (s2 == NULL ? 0 : strlen (s2));
1276 s3 = g_malloc0 (sz + 1);
1278 memcpy (s3, s1 != NULL ? s1 : tc1->x.str_val, len1);
1280 memcpy (s3 + len1, s2 != NULL ? s2 : tc2->x.str_val, len2);
1299#ifdef STOP_AT_FIRST_ERROR
1306#ifdef STOP_AT_FIRST_ERROR
1352 p1 = tc1->x.str_val;
1358 len1 = (s1 == NULL ? 0 : strlen (s1));
1363 p2 = tc2->x.str_val;
1369 len2 = (s2 == NULL ? 0 : strlen (s2));
1374 if (len2 == 0 || len1 < len2
1375 || (p1 != NULL && (p = memmem (p1, len1, p2, len2)) == NULL))
1377 s3 = g_malloc0 (len1 + 1);
1379 memcpy (s3, p1, len1);
1386 long sz = len1 - len2;
1394 s3 = g_malloc0 (sz + 1);
1396 memcpy (s3, p1, p - p1);
1397 if (p != NULL && sz > p - p1)
1398 memcpy (s3 + (p - p1), p + len2, sz - (p - p1));
1477 if (x < 0 && z >= 0)
1478 z |= (~0) << (
sizeof (x) * 8 - y);
1485 z = (unsigned) x >> (
unsigned) y;
1487 if (x < 0 && z <= 0)
1488 z &= ~((~0) << (
sizeof (x) * 8 - y));
1505 p1 = tc1->x.str_val;
1521 p2 = tc2->x.str_val;
1531 flag = (memmem (p2, len2, p1, len1) != NULL);
1548 nasl_perror (lexic,
"nasl_exec: bad regex at or near line %d\n",
1555 flag = regexec (st->
x.
ref_val, s1, 0, NULL, 0);
1626 gchar *short_name = g_path_get_basename (
name);
1627 int error_counter = 0;
1630 g_free (short_name);
1632 srand48 (getpid () + getppid () + (
long) time (NULL));
1634 old_dir = g_get_current_dir ();
1636 newdir = g_path_get_dirname (
name);
1638 if (g_chdir (newdir) != 0)
1640 g_message (
"%s: Not able to change working directory to %s (%d [%s]).",
1641 __func__, newdir, errno, strerror (errno));
1648 bzero (&ctx,
sizeof (ctx));
1653 if (nvticache_initialized ())
1654 ctx.
kb = nvticache_get_kb ();
1661 if (err != 0 || error_counter > 0)
1663 g_message (
"%s. There were %d parse errors.",
name, error_counter);
1682 str = prefs_get (
"checks_read_timeout");
1700 if (lintret == NULL)
1712 bzero (&tc,
sizeof (tc));
1717 bzero (&tc,
sizeof (tc));
1724 name_aux = g_strdup (
name);
1725 p = strrchr (name_aux,
'/');
1727 p = (
char *) name_aux;
1732 tc.
size = strlen (p);
1747 if (g_chdir (old_dir) != 0)
long int cell_cmp(lex_ctxt *lexic, tree_cell *c1, tree_cell *c2)
static long int cell2intW(lex_ctxt *lexic, 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_cell * cell2atom(lex_ctxt *lexic, tree_cell *c1)
static void nasl_dump_expr(FILE *fp, const tree_cell *c)
static tree_cell * bool2cell(long int x)
int naslparse(naslctxt *, int *)
int exec_nasl_script(struct script_infos *script_infos, int mode)
Execute a NASL script.
static int cell2bool(lex_ctxt *lexic, tree_cell *c)
static tree_cell * int2cell(long int x)
tree_cell * nasl_exec(lex_ctxt *lexic, tree_cell *st)
Execute a parse tree.
static long int cell2int(lex_ctxt *lexic, tree_cell *c)
static long int cell2int3(lex_ctxt *lexic, tree_cell *c, int warn, named_nasl_var *v)
static char * cell2str(lex_ctxt *lexic, tree_cell *c)
tree_cell * nasl_lint(lex_ctxt *lexic, tree_cell *st)
Search for errors in a nasl script.
#define NASL_ALWAYS_SIGNED
#define NASL_EXEC_PARSE_ONLY
#define NASL_COMMAND_LINE
void nasl_set_filename(const char *filename)
void nasl_set_plugin_filename(const char *filename)
Set the current launched plugin filename.
void nasl_perror(lex_ctxt *lexic, char *msg,...)
tree_cell * nasl_func_call(lex_ctxt *lexic, const nasl_func *f, tree_cell *arg_list)
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_return(lex_ctxt *ctxt, tree_cell *retv)
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 *)
void nasl_okrb5_clean(void)
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 *)
tree_cell * nasl_incr_variable(lex_ctxt *, tree_cell *, int, int)
struct struct_lex_ctxt lex_ctxt
tree_cell * get_array_elem(lex_ctxt *, const char *, tree_cell *)
tree_cell * nasl_read_var_ref(lex_ctxt *, tree_cell *)
tree_cell * decl_global_variables(lex_ctxt *, tree_cell *)
tree_cell * decl_local_variables(lex_ctxt *, tree_cell *)
tree_cell * get_variable_by_name(lex_ctxt *, const char *)
void ref_cell(tree_cell *c)
int cell_type(const tree_cell *c)
const char * nasl_type_name(int t)
tree_cell * alloc_expr_cell(int lnb, int t, tree_cell *l, tree_cell *r)
tree_cell * alloc_typed_cell(int typ)
void deref_cell(tree_cell *c)
nasl_iterator nasl_array_iterator(void *ctxt, tree_cell *c)
tree_cell * nasl_iterate_array(nasl_iterator *it)
tree_cell * nasl_affect(tree_cell *lval, tree_cell *rval)
char * array2str(const nasl_array *a)
void free_array(nasl_array *a)
struct st_nasl_array nasl_array
struct st_n_nasl_var named_nasl_var
kb_t plug_get_kb(struct script_infos *args)
Header file for module plugutils.
union TC::@332262321161220155002104006201360276211317150140 x
struct script_infos * script_infos