summaryrefslogtreecommitdiffstats
path: root/src/payload.c
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2010-07-06 05:57:22 +0200
committerPatrick McHardy <kaber@trash.net>2010-07-06 05:57:22 +0200
commit10ce8775690f890bc4f6546f2b306bc9f87b6fe2 (patch)
tree6ff7df99ef6430f08fa310093a5eaf4ab21e7ece /src/payload.c
parentd4aea11c6a7674e4290dc71a4ac93c1d5be7240d (diff)
payload: fix crash with uncombinable protocols
The dependency of non-combinable protocols (f.i. arp + tcp) results in a relational dependency expression without a datatype, causing a segfault later on. Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'src/payload.c')
-rw-r--r--src/payload.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/payload.c b/src/payload.c
index 003d84b8..611697ec 100644
--- a/src/payload.c
+++ b/src/payload.c
@@ -141,8 +141,8 @@ payload_select_proto(const struct payload_desc *base, unsigned int num)
* @base: lower layer protocol description
* @desc: upper layer protocol description
*/
-static unsigned int payload_proto_val(const struct payload_desc *base,
- const struct payload_desc *desc)
+static int payload_proto_val(const struct payload_desc *base,
+ const struct payload_desc *desc)
{
unsigned int i;
@@ -150,7 +150,7 @@ static unsigned int payload_proto_val(const struct payload_desc *base,
if (base->protocols[i].desc == desc)
return base->protocols[i].num;
}
- return 0;
+ return -1;
}
static const struct dev_payload_desc dev_payload_desc[] = {
@@ -297,7 +297,7 @@ int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr,
const struct payload_desc *desc;
const struct payload_template *tmpl;
struct expr *dep, *left, *right;
- unsigned int protocol;
+ int protocol;
uint16_t type;
if (expr->payload.base < h->base) {
@@ -328,9 +328,14 @@ int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr,
"no %s protocol specified",
payload_base_names[expr->payload.base - 1]);
+ protocol = payload_proto_val(desc, expr->payload.desc);
+ if (protocol < 0)
+ return expr_error(ctx, expr,
+ "conflicting protocols specified: %s vs. %s",
+ desc->name, expr->payload.desc->name);
+
tmpl = &desc->templates[desc->protocol_key];
left = payload_expr_alloc(&expr->location, desc, desc->protocol_key);
- protocol = payload_proto_val(desc, expr->payload.desc);
right = constant_expr_alloc(&expr->location, tmpl->dtype,
BYTEORDER_HOST_ENDIAN,
tmpl->len, &protocol);