datatype: fix crash when using basetype instead of symbolic constants
Pablo Neira Ayuso
maintainerPATCH 1/1 datatype: fix crash when using basetype instead of symbolic constants
The following example:
# nft add rule filter input ct state 8 accept Segmentation fault
leads to a crash because we have the following datatype relation:
ct_state -> bitmask -> integer
The bitmask, which is an intermediate basetype, has no parse() function, this leads to a crash in symbolic_constant_parse().
So let's default to the leaf basetype parser when the intermediate one has no specific parser() function.
Add a bugtrap too to catch inconsistent datatype configurations.
--- src/datatype.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
src/datatype.c +11 -1
@@ -128,7 +128,17 @@ struct error_record *symbolic_constant_parse(const struct expr *sym, dtype = sym->dtype;if (s->identifier ==NULL ) { *res =NULL ; - erec = sym->dtype->basetype->parse (sym, res); + +if (sym->dtype->basetype->parse) { + erec = sym->dtype->basetype->parse (sym, res); + }else if (sym->dtype->basetype->basetype && + sym->dtype->basetype->basetype->parse) { + erec = sym->dtype->basetype->basetype->parse (sym, res); + }else { +BUG ("cannot parse symbol %s with datatype %s\n" , + sym->identifier, sym->dtype->basetype->name); + } +if (erec !=NULL )return erec;if (*res)
Signature · 1 line
1.7.10.4
Quoted 9 lines · Pablo Neira Ayuso
The following example:
# nft add rule filter input ct state 8 accept Segmentation faultleads to a crash because we have the following datatype relation:
ct_state-> bitmask -> integer
Quoted 7 lines
The bitmask, which is an intermediate basetype, has no
parse()function, this leads to a crash insymbolic_constant_parse().So let's default to the leaf basetype parser when the intermediate one has no specific
parser()function.Add a bugtrap too to catch inconsistent datatype configurations.
I think we should just walk down the chain until we find something with a parse function.