Execute a parse tree.
- Todo
- There is a lot of duplicated code in following cases, could be refactored.
Definition at line 770 of file exec.c.
771{
772 tree_cell *ret = NULL, *ret2 = NULL, *tc1 = NULL, *tc2 = NULL, *tc3 = NULL,
773 *idx = NULL, *args;
774 int flag, z;
775 char *s1 = NULL, *s2 = NULL, *s3 = NULL, *p = NULL;
776 char *p1, *p2;
777 int len1, len2;
779 long int x, y, n;
780 int i, lint_mode = 0;
781
782 if (st)
785
787 {
790 }
791
792
795
798
799 if (st == NULL)
800 {
801 return NULL;
802 }
803
806
808 {
811#ifdef STOP_AT_FIRST_ERROR
812 if (ret == NULL)
813 return NULL;
814#endif
817 else if (st->
link[2] != NULL)
819 else
822 return ret2;
823
827 return ret;
830 return ret;
831
833
835#ifdef STOP_AT_FIRST_ERROR
836 if (ret2 == NULL)
837 return NULL;
838#endif
840 for (;;)
841 {
842
844 {
847 }
848
849
851 return NULL;
854 if (!flag)
855 break;
856
858#ifdef STOP_AT_FIRST_ERROR
859 if (ret == NULL)
860 return NULL;
861#endif
863
864
866 {
869 }
870
872
873
875#ifdef STOP_AT_FIRST_ERROR
876 if (ret == NULL)
877 return NULL;
878#endif
880 }
882
884
885 for (;;)
886 {
887
889 {
892 }
893
895 return NULL;
898 if (!flag)
899 break;
900
902#ifdef STOP_AT_FIRST_ERROR
903 if (ret == NULL)
904 return NULL;
905#endif
907
908
910 {
913 }
915 }
917
919
920 for (;;)
921 {
922
924 {
927 }
928
930#ifdef STOP_AT_FIRST_ERROR
931 if (ret == NULL)
932 return NULL;
933#endif
935
936
938 {
941 }
943
944
946#ifdef STOP_AT_FIRST_ERROR
947 if (ret == NULL)
948 return NULL;
949#endif
952 if (flag)
953 break;
954 }
956
958
959 {
962
964 if (v == NULL)
965 return NULL;
969 {
974#ifdef STOP_AT_FIRST_ERROR
975 if (ret == NULL)
976 break;
977#endif
979
980
982 break;
983
985 {
987 break;
988 }
990 }
995 }
997
999
1000
1002 return ret;
1003
1006 if (pf == NULL)
1007 {
1009 return NULL;
1010 }
1013 return ret;
1014
1017 if (n <= 0)
1018 return NULL;
1019
1020#ifdef STOP_AT_FIRST_ERROR
1021 for (tc1 = NULL, i = 1; i <= n; i++)
1022 {
1025 return NULL;
1026 }
1027 return tc1;
1028#else
1029 for (i = 1; i <= n; i++)
1030 {
1033 }
1035#endif
1036
1037
1038
1039
1040
1042
1043
1044 return st;
1045
1047
1049 return ret;
1050
1052
1054 return ret;
1055
1059
1063
1068 return ret;
1069
1073
1079 return tc2;
1080
1089 return ret2;
1090
1099 return ret2;
1100
1109 return ret2;
1110
1119 return ret2;
1120
1129 return ret2;
1130
1139 return ret2;
1140
1149 return ret2;
1150
1159 return ret2;
1160
1162
1164 return ret;
1165
1168 return ret;
1169
1172 return ret;
1173
1176 if (!x)
1178
1181
1184 if (x)
1188
1192
1196 if (st->
link[0] == NULL)
1197 {
1198 y = 1;
1200 }
1201 else
1202 {
1203 y = 0;
1205 }
1207 if (tc2 == NULL)
1208 return NULL;
1211 return ret;
1212
1214 s1 = s2 = NULL;
1216#ifdef STOP_AT_FIRST_ERROR
1218 return NULL;
1219#endif
1222 {
1223#ifdef STOP_AT_FIRST_ERROR
1225 return NULL;
1226#else
1227 return tc1;
1228#endif
1229 }
1230
1232 return tc2;
1233
1234
1235
1236
1237
1244 else
1246 switch (flag)
1247 {
1248 long sz;
1250 x = tc1->x.i_val;
1253 break;
1254
1257 s1 = s2 = NULL;
1259 len1 = tc1->size;
1260 else
1261 {
1263 len1 = (s1 == NULL ? 0 : strlen (s1));
1264 }
1265
1267 len2 = tc2->size;
1268 else
1269 {
1271 len2 = (s2 == NULL ? 0 : strlen (s2));
1272 }
1273
1274 sz = len1 + len2;
1275 s3 = g_malloc0 (sz + 1);
1276 if (len1 > 0)
1277 memcpy (s3, s1 != NULL ? s1 : tc1->x.str_val, len1);
1278 if (len2 > 0)
1279 memcpy (s3 + len1, s2 != NULL ? s2 : tc2->x.str_val, len2);
1280 g_free (s1);
1281 g_free (s2);
1285 break;
1286
1287 default:
1288 ret = NULL;
1289 break;
1290 }
1293 return ret;
1294
1296 s1 = s2 = NULL;
1298#ifdef STOP_AT_FIRST_ERROR
1300 return NULL;
1301#endif
1304 {
1305#ifdef STOP_AT_FIRST_ERROR
1307 return NULL;
1308#else
1309 return tc1;
1310#endif
1311 }
1312
1314 {
1316 {
1319 }
1320 else
1321 ret = NULL;
1323 return ret;
1324 }
1325
1326
1327
1328
1329
1330
1337 else
1339 switch (flag)
1340 {
1345 break;
1346
1350 {
1351 p1 = tc1->x.str_val;
1352 len1 = tc1->size;
1353 }
1354 else
1355 {
1357 len1 = (s1 == NULL ? 0 : strlen (s1));
1358 }
1359
1361 {
1362 p2 = tc2->x.str_val;
1363 len2 = tc2->size;
1364 }
1365 else
1366 {
1368 len2 = (s2 == NULL ? 0 : strlen (s2));
1369 }
1370
1371
1372
1373 if (len2 == 0 || len1 < len2
1374 || (p1 != NULL && (p = memmem (p1, len1, p2, len2)) == NULL))
1375 {
1376 s3 = g_malloc0 (len1 + 1);
1377 if (p1 != NULL)
1378 memcpy (s3, p1, len1);
1382 }
1383 else
1384 {
1385 long sz = len1 - len2;
1386 if (sz <= 0)
1387 {
1388 sz = 0;
1389 s3 = g_strdup ("");
1390 }
1391 else
1392 {
1393 s3 = g_malloc0 (sz + 1);
1394 if (p - p1 > 0)
1395 memcpy (s3, p1, p - p1);
1396 if (p != NULL && sz > p - p1)
1397 memcpy (s3 + (p - p1), p + len2, sz - (p - p1));
1398 }
1402 }
1403
1404 g_free (s1);
1405 g_free (s2);
1406 break;
1407
1408 default:
1409 ret = NULL;
1410 break;
1411 }
1414 return ret;
1415
1420
1424 if (y != 0)
1426 else
1428
1433
1437 if (y != 0)
1439 else
1441
1446
1451
1456
1460
1464
1465
1470
1474 z = x >> y;
1475#ifndef __GNUC__
1476 if (x < 0 && z >= 0)
1477 z |= (~0) << (sizeof (x) * 8 - y);
1478#endif
1480
1484 z = (unsigned) x >> (unsigned) y;
1485#ifndef __GNUC__
1486 if (x < 0 && z <= 0)
1487 z &= ~((~0) << (sizeof (x) * 8 - y));
1488#endif
1490
1495 s1 = s2 = NULL;
1496
1498 {
1499 p1 = "";
1500 len1 = 0;
1501 }
1503 {
1504 p1 = tc1->x.str_val;
1505 len1 = tc1->size;
1506 }
1507 else
1508 {
1510 len1 = strlen (s1);
1511 }
1512
1514 {
1515 p2 = "";
1516 len2 = 0;
1517 }
1519 {
1520 p2 = tc2->x.str_val;
1521 len2 = tc2->size;
1522 }
1523 else
1524 {
1526 len2 = strlen (s2);
1527 }
1528
1529 if (len1 <= len2)
1530 flag = (memmem (p2, len2, p1, len1) != NULL);
1531 else
1532 flag = 0;
1533
1534 g_free (s1);
1535 g_free (s2);
1540 else
1542
1546 {
1547 nasl_perror (lexic,
"nasl_exec: bad regex at or near line %d\n",
1549 return NULL;
1550 }
1552 if (s1 == NULL)
1553 return 0;
1554 flag = regexec (st->
x.
ref_val, s1, 0, NULL, 0);
1555 g_free (s1);
1558 else
1560
1563
1566
1569
1572
1575
1578
1585 return st;
1586
1589 return ret;
1590
1591 default:
1593 abort ();
1594 return NULL;
1595 }
1596}
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)
static tree_cell * bool2cell(long int x)
static int cell2bool(lex_ctxt *lexic, tree_cell *c)
static tree_cell * int2cell(long int x)
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
tree_cell * nasl_incr_variable(lex_ctxt *, tree_cell *, int, int)
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 *)
tree_cell * alloc_expr_cell(int lnb, int t, tree_cell *l, tree_cell *r)
tree_cell * alloc_typed_cell(int typ)
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)
void free_array(nasl_array *a)
union TC::@332262321161220155002104006201360276211317150140 x
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().