forked from osmocom/wireshark
dfilter: Fix memory leak with leading colon
When retrying fvalue_from_literal() we were leaking the error
message string.
Refactor the code to avoid the retry. This assumes the only
valid use of a leading ':' with a literal is for an IPv6 address.
Bytes with leading ':' are supported but the colon is skipped,
so the parser doesn't see it.
Fixes df0fc8b517
.
This commit is contained in:
parent
85be944ebe
commit
8108e67de7
|
@ -378,8 +378,12 @@ v6-cidr-prefix \/[[:digit:]]{1,3}
|
|||
return set_lval_str(TOKEN_UNPARSED, yytext);
|
||||
}
|
||||
|
||||
[[:xdigit:]]+:[[:xdigit:]:]* {
|
||||
:?[[:xdigit:]]+:[[:xdigit:]:]* {
|
||||
/* Bytes. */
|
||||
if (yytext[0] == ':') {
|
||||
/* Skip leading colon. */
|
||||
return set_lval_str(TOKEN_LITERAL, yytext + 1);
|
||||
}
|
||||
return set_lval_str(TOKEN_UNPARSED, yytext);
|
||||
}
|
||||
|
||||
|
@ -392,8 +396,10 @@ v6-cidr-prefix \/[[:digit:]]{1,3}
|
|||
/* Identifier or literal or unparsed. */
|
||||
if (yytext[0] == '.')
|
||||
return set_lval_str(TOKEN_IDENTIFIER, yytext);
|
||||
if (yytext[0] == ':')
|
||||
return set_lval_str(TOKEN_LITERAL, yytext);
|
||||
if (yytext[0] == ':') {
|
||||
/* Skip leading colon. */
|
||||
return set_lval_str(TOKEN_LITERAL, yytext + 1);
|
||||
}
|
||||
return set_lval_str(TOKEN_UNPARSED, yytext);
|
||||
}
|
||||
|
||||
|
|
|
@ -372,14 +372,7 @@ fvalue_from_literal(ftenum_t ftype, const char *s, gboolean allow_partial_value,
|
|||
|
||||
fv = fvalue_new(ftype);
|
||||
if (fv->ftype->val_from_literal) {
|
||||
if (*s == ':') {
|
||||
ok = fv->ftype->val_from_literal(fv, s + 1, allow_partial_value, err_msg);
|
||||
/* If not ok maybe leading colon is not special syntax but part of the value (e.g: IPv6),
|
||||
* try again in that case. */
|
||||
}
|
||||
if (!ok) {
|
||||
ok = fv->ftype->val_from_literal(fv, s, allow_partial_value, err_msg);
|
||||
}
|
||||
ok = fv->ftype->val_from_literal(fv, s, allow_partial_value, err_msg);
|
||||
if (ok) {
|
||||
/* Success */
|
||||
if (err_msg != NULL)
|
||||
|
|
Loading…
Reference in New Issue