summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-05-10 16:34:09 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-05-10 16:34:09 +0200
commit87683f08c709b00cd26ff0903f91a66f934a14db (patch)
treee59c462af93248b571950dc378a95bb744725f3e
parente6ddf6d5424c3914dbaa9801244ddb24c03b7917 (diff)
trafgen: lexer: also allow short forms for hex and binary
Also allow for ... - hex: 0xff, xff - binary: 0b11110000, b11110000 Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
-rw-r--r--trafgen_lexer.l10
1 files changed, 6 insertions, 4 deletions
diff --git a/trafgen_lexer.l b/trafgen_lexer.l
index 20b6efe..ca5bff9 100644
--- a/trafgen_lexer.l
+++ b/trafgen_lexer.l
@@ -71,8 +71,8 @@ static char *try_convert_shellcode(char *sstr)
%option nodefault
number_oct ([0][0-9]+)
-number_hex ([0][x][a-fA-F0-9]+)
-number_bin ([0][b][0-1]+)
+number_hex ([0]?[x][a-fA-F0-9]+)
+number_bin ([0]?[b][0-1]+)
number_dec (([0])|([1-9][0-9]*))
number_ascii ([a-zA-Z])
@@ -128,7 +128,8 @@ number_ascii ([a-zA-Z])
"#"[^\n]* { return K_COMMENT; }
-{number_hex} { yylval.number = strtoul(yytext, NULL, 16);
+{number_hex} { yylval.number = strtoul(yytext + (yytext[0] == 'x' ? 1 : 0),
+ NULL, 16);
return number; }
{number_dec} { yylval.number = strtol(yytext, NULL, 10);
@@ -137,7 +138,8 @@ number_ascii ([a-zA-Z])
{number_oct} { yylval.number = strtol(yytext + 1, NULL, 8);
return number; }
-{number_bin} { yylval.number = strtol(yytext + 2, NULL, 2);
+{number_bin} { yylval.number = strtol(yytext + (yytext[0] == 'b' ? 1 : 2),
+ NULL, 2);
return number; }
{number_ascii} { yylval.number = (uint8_t) (*yytext);