evaluate: print error for null string befort assert statement
PATCH 1/1 evaluate: print error for null string befort assert statement
Print error "Null string is not allowed" before assert statement. For e.g.
nft add rule filter input meta iifname '""'
Error: Null String is not allowed
add rule filter input meta iifname ""
--- src/evaluate.c | 4 ++++ 1 file changed, 4 insertions(+)
src/evaluate.c +4 -0
@@ -235,6 +235,10 @@ static int expr_evaluate_string(struct eval_ctx *ctx, struct expr **exprp)memset (data + len,0 , data_len - len);mpz_export_data (data, expr->value,BYTEORDER_HOST_ENDIAN , len); +if (strlen (data) ==0 ) { +return expr_error (ctx->msgs, expr, +"Null String is not allowed" ); + }assert (strlen (data) >0 ); datalen =strlen (data) -1 ;if (data[datalen] !='*' ) {
Signature · 1 line
2.11.0
Florian Westphal
maintainerQuoted 5 lines · Harsha Sharma
Print error "Null string is not allowed" before assert statement. For e.g.
nft add rule filter input meta iifname '""'
Error: Null String is not allowed
add rule filter input meta iifname ""
Is there any case where "" should be allowed?
If not, I'd rather change scanner.l to not recognize "" as a quoted string.
Pablo Neira Ayuso
maintainerQuoted 11 lines · Florian Westphal
Quoted 5 lines · Harsha Sharma
Print error "Null string is not allowed" before assert statement. For e.g.
nft add rule filter input meta iifname '""'
Error: Null String is not allowed
add rule filter input meta iifname ""Is there any case where "" should be allowed?
If not, I'd rather change scanner.l to not recognize "" as a quoted string.
We'll get error reporting like this if we handle this from the scanner:
# nft add rule x y ct label \"\"
Error: syntax error, unexpected junk
add rule x y ct label ""
^This is just two extra lines in the validation step and it is not worth to optimize an error case, ie. do it earlier. So I'm feeling inclined to take this one.
I will mangle the error message to "Empty string is not allowed". "Null" probably sounds too programmer thing.
Thanks!
Florian Westphal
maintainerQuoted 13 lines · Pablo Neira Ayuso
Quoted 11 lines · Florian Westphal
Quoted 5 lines · Harsha Sharma
Print error "Null string is not allowed" before assert statement. For e.g.
nft add rule filter input meta iifname '""'
Error: Null String is not allowed
add rule filter input meta iifname ""Is there any case where "" should be allowed?
If not, I'd rather change scanner.l to not recognize "" as a quoted string.
Quoted 6 lines
We'll get error reporting like this if we handle this from the scanner:
# nft add rule x y ct label \"\" Error: syntax error, unexpected junk add rule x y ct label ""
Right, we'd have to add dummy empty_string rule to avoid this.
Quoted 3 lines
This is just two extra lines in the validation step and it is not worth to optimize an error case, ie. do it earlier. So I'm feeling inclined to take this one.
Makes sense to me.
Quoted 2 lines
I will mangle the error message to "Empty string is not allowed". "Null" probably sounds too programmer thing.
Can you also get rid of the assert(strlen ... line? Its useless after this patch.
Thanks!
Pablo Neira Ayuso
maintainerQuoted 27 lines · Florian Westphal
Quoted 13 lines · Pablo Neira Ayuso
Quoted 11 lines · Florian Westphal
Quoted 5 lines · Harsha Sharma
Print error "Null string is not allowed" before assert statement. For e.g.
nft add rule filter input meta iifname '""'
Error: Null String is not allowed
add rule filter input meta iifname ""Is there any case where "" should be allowed?
If not, I'd rather change scanner.l to not recognize "" as a quoted string.
Quoted 6 lines
We'll get error reporting like this if we handle this from the scanner:
# nft add rule x y ct label \"\" Error: syntax error, unexpected junk add rule x y ct label ""Right, we'd have to add dummy
empty_stringrule to avoid this.Quoted 3 lines
This is just two extra lines in the validation step and it is not worth to optimize an error case, ie. do it earlier. So I'm feeling inclined to take this one.
Quoted 7 lines
Makes sense to me.
Quoted 2 lines
I will mangle the error message to "Empty string is not allowed". "Null" probably sounds too programmer thing.
Can you also get rid of the assert(strlen ... line? Its useless after this patch.
Indeed, done!