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;
780 long int x, y, n;
781 int i, lint_mode = 0;
782
783 if (st)
786
788 {
791 }
792
793
796
799
800 if (st == NULL)
801 {
802 return NULL;
803 }
804
807
809 {
812#ifdef STOP_AT_FIRST_ERROR
813 if (ret == NULL)
814 return NULL;
815#endif
818 else if (st->
link[2] != NULL)
820 else
823 return ret2;
824
828 return ret;
831 return ret;
832
834
836#ifdef STOP_AT_FIRST_ERROR
837 if (ret2 == NULL)
838 return NULL;
839#endif
841 for (;;)
842 {
843
845 {
848 }
849
850
852 return NULL;
855 if (!flag)
856 break;
857
859#ifdef STOP_AT_FIRST_ERROR
860 if (ret == NULL)
861 return NULL;
862#endif
864
865
867 {
870 }
871
873
874
876#ifdef STOP_AT_FIRST_ERROR
877 if (ret == NULL)
878 return NULL;
879#endif
881 }
883
885
886 for (;;)
887 {
888
890 {
893 }
894
896 return NULL;
899 if (!flag)
900 break;
901
903#ifdef STOP_AT_FIRST_ERROR
904 if (ret == NULL)
905 return NULL;
906#endif
908
909
911 {
914 }
916 }
918
920
921 for (;;)
922 {
923
925 {
928 }
929
931#ifdef STOP_AT_FIRST_ERROR
932 if (ret == NULL)
933 return NULL;
934#endif
936
937
939 {
942 }
944
945
947#ifdef STOP_AT_FIRST_ERROR
948 if (ret == NULL)
949 return NULL;
950#endif
953 if (flag)
954 break;
955 }
957
959
960 {
963
965 if (v == NULL)
966 return NULL;
970 {
975#ifdef STOP_AT_FIRST_ERROR
976 if (ret == NULL)
977 break;
978#endif
980
981
983 break;
984
986 {
988 break;
989 }
991 }
996 }
998
1000
1001
1003 return ret;
1004
1007 if (pf == NULL)
1008 {
1010 return NULL;
1011 }
1014 return ret;
1015
1018 if (n <= 0)
1019 return NULL;
1020
1021#ifdef STOP_AT_FIRST_ERROR
1022 for (tc1 = NULL, i = 1; i <= n; i++)
1023 {
1026 return NULL;
1027 }
1028 return tc1;
1029#else
1030 for (i = 1; i <= n; i++)
1031 {
1034 }
1036#endif
1037
1038
1039
1040
1041
1043
1044
1045 return st;
1046
1048
1050 return ret;
1051
1053
1055 return ret;
1056
1060
1064
1069 return ret;
1070
1074
1080 return tc2;
1081
1090 return ret2;
1091
1100 return ret2;
1101
1110 return ret2;
1111
1120 return ret2;
1121
1130 return ret2;
1131
1140 return ret2;
1141
1150 return ret2;
1151
1160 return ret2;
1161
1163
1165 return ret;
1166
1169 return ret;
1170
1173 return ret;
1174
1177 if (!x)
1179
1182
1185 if (x)
1189
1193
1197 if (st->
link[0] == NULL)
1198 {
1199 y = 1;
1201 }
1202 else
1203 {
1204 y = 0;
1206 }
1208 if (tc2 == NULL)
1209 return NULL;
1212 return ret;
1213
1215 s1 = s2 = NULL;
1217#ifdef STOP_AT_FIRST_ERROR
1219 return NULL;
1220#endif
1223 {
1224#ifdef STOP_AT_FIRST_ERROR
1226 return NULL;
1227#else
1228 return tc1;
1229#endif
1230 }
1231
1233 return tc2;
1234
1235
1236
1237
1238
1245 else
1247 switch (flag)
1248 {
1249 long sz;
1251 x = tc1->x.i_val;
1254 break;
1255
1258 s1 = s2 = NULL;
1260 len1 = tc1->size;
1261 else
1262 {
1264 len1 = (s1 == NULL ? 0 : strlen (s1));
1265 }
1266
1268 len2 = tc2->size;
1269 else
1270 {
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);
1286 break;
1287
1288 default:
1289 ret = NULL;
1290 break;
1291 }
1294 return ret;
1295
1297 s1 = s2 = NULL;
1299#ifdef STOP_AT_FIRST_ERROR
1301 return NULL;
1302#endif
1305 {
1306#ifdef STOP_AT_FIRST_ERROR
1308 return NULL;
1309#else
1310 return tc1;
1311#endif
1312 }
1313
1315 {
1317 {
1320 }
1321 else
1322 ret = NULL;
1324 return ret;
1325 }
1326
1327
1328
1329
1330
1331
1338 else
1340 switch (flag)
1341 {
1346 break;
1347
1351 {
1352 p1 = tc1->x.str_val;
1353 len1 = tc1->size;
1354 }
1355 else
1356 {
1358 len1 = (s1 == NULL ? 0 : strlen (s1));
1359 }
1360
1362 {
1363 p2 = tc2->x.str_val;
1364 len2 = tc2->size;
1365 }
1366 else
1367 {
1369 len2 = (s2 == NULL ? 0 : strlen (s2));
1370 }
1371
1372
1373
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);
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 }
1403 }
1404
1405 g_free (s1);
1406 g_free (s2);
1407 break;
1408
1409 default:
1410 ret = NULL;
1411 break;
1412 }
1415 return ret;
1416
1421
1425 if (y != 0)
1427 else
1429
1434
1438 if (y != 0)
1440 else
1442
1447
1452
1457
1461
1465
1466
1471
1475 z = x >> y;
1476#ifndef __GNUC__
1477 if (x < 0 && z >= 0)
1478 z |= (~0) << (sizeof (x) * 8 - y);
1479#endif
1481
1485 z = (unsigned) x >> (unsigned) y;
1486#ifndef __GNUC__
1487 if (x < 0 && z <= 0)
1488 z &= ~((~0) << (sizeof (x) * 8 - y));
1489#endif
1491
1496 s1 = s2 = NULL;
1497
1499 {
1500 p1 = "";
1501 len1 = 0;
1502 }
1504 {
1505 p1 = tc1->x.str_val;
1506 len1 = tc1->size;
1507 }
1508 else
1509 {
1511 len1 = strlen (s1);
1512 }
1513
1515 {
1516 p2 = "";
1517 len2 = 0;
1518 }
1520 {
1521 p2 = tc2->x.str_val;
1522 len2 = tc2->size;
1523 }
1524 else
1525 {
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);
1541 else
1543
1547 {
1548 nasl_perror (lexic,
"nasl_exec: bad regex at or near line %d\n",
1550 return NULL;
1551 }
1553 if (s1 == NULL)
1554 return 0;
1555 flag = regexec (st->
x.
ref_val, s1, 0, NULL, 0);
1556 g_free (s1);
1559 else
1561
1564
1567
1570
1573
1576
1579
1586 return st;
1587
1590 return ret;
1591
1592 default:
1594 abort ();
1595 return NULL;
1596 }
1597}
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().