Skip to content

Commit

Permalink
Change: consider a malformed regex as a nasl parse error for built-in…
Browse files Browse the repository at this point in the history
… RE_MATCH and RE_NOMATCH (#1057)
  • Loading branch information
jjnicola committed Mar 17, 2022
1 parent b8d22c4 commit 986f2c6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions nasl/nasl_grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define YYLEX_ERRC err_c

#define LNB (((naslctxt*)parm)->line_nb)
#define ERRC err_c

#include <ctype.h> /* for isalpha */
#include <pcap.h> /* for islocalhost */
Expand Down Expand Up @@ -460,8 +461,8 @@ expr: '(' expr ')' { $$ = $2; }
| post_pre_incr
| expr MATCH expr { $$ = alloc_expr_cell(LNB, COMP_MATCH, $1, $3); }
| expr NOMATCH expr { $$ = alloc_expr_cell(LNB, COMP_NOMATCH, $1, $3); }
| expr RE_MATCH string { $$ = alloc_RE_cell(LNB, COMP_RE_MATCH, $1, $3); }
| expr RE_NOMATCH string { $$ = alloc_RE_cell(LNB, COMP_RE_NOMATCH, $1, $3); }
| expr RE_MATCH string { $$ = alloc_RE_cell(LNB, COMP_RE_MATCH, $1, $3, ERRC); }
| expr RE_NOMATCH string { $$ = alloc_RE_cell(LNB, COMP_RE_NOMATCH, $1, $3, ERRC); }
| expr '<' expr { $$ = alloc_expr_cell(LNB, COMP_LT, $1, $3); }
| expr '>' expr { $$ = alloc_expr_cell(LNB, COMP_GT, $1, $3); }
| expr EQ expr { $$ = alloc_expr_cell(LNB, COMP_EQ, $1, $3); }
Expand Down
3 changes: 2 additions & 1 deletion nasl/nasl_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ alloc_typed_cell (int typ)
}

tree_cell *
alloc_RE_cell (int lnb, int t, tree_cell *l, char *re_str)
alloc_RE_cell (int lnb, int t, tree_cell *l, char *re_str, int *err_c)
{
regex_t *re = g_malloc0 (sizeof (regex_t));
int e;
Expand All @@ -65,6 +65,7 @@ alloc_RE_cell (int lnb, int t, tree_cell *l, char *re_str)
nasl_perror (NULL, "Line %d: Cannot compile regex: %s (error %d: %s)\n",
lnb, re_str, e, errbuf);
g_free (re);
*err_c = *err_c + 1;
}
g_free (re_str);
return c;
Expand Down
2 changes: 1 addition & 1 deletion nasl/nasl_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ typedef struct TC
tree_cell *
alloc_expr_cell (int, int, tree_cell *, tree_cell *);
tree_cell *
alloc_RE_cell (int, int, tree_cell *, char *);
alloc_RE_cell (int, int, tree_cell *, char *, int *);
tree_cell *
alloc_typed_cell (int);
int
Expand Down

0 comments on commit 986f2c6

Please sign in to comment.