Fix hangs in nmrp code

This commit is contained in:
Joseph C. Lehner 2016-11-18 16:53:21 +01:00
parent b690785498
commit 03ffca3544

27
nmrp.c
View file

@ -144,27 +144,6 @@ static void msg_dump(struct nmrp_msg *msg, int dump_opts)
remain_len = msg->len - NMRP_HDR_LEN;
fprintf(stderr, "%s\n", remain_len ? "" : " (no opts)");
if (dump_opts) {
opt = msg->opts;
while (remain_len > 0) {
len = opt->len;
fprintf(stderr, " opt type=%u, len=%u", opt->type, len);
if (len) {
for (i = 0; i != len - NMRP_OPT_HDR_LEN; ++i) {
if (!(i % 16)) {
fprintf(stderr, "\n ");
}
fprintf(stderr, "%02x ", ((char*)&opt->val)[i] & 0xff);
}
fprintf(stderr, "\n");
}
remain_len -= len;
opt = NMRP_OPT_NEXT(opt);
}
}
}
static void msg_hton(struct nmrp_msg *msg)
@ -207,7 +186,7 @@ static int msg_ntoh(struct nmrp_msg *msg)
opt->type = ntohs(opt->type);
opt->len = ntohs(opt->len);
if (opt->len > NMRP_MAX_OPT_SIZE) {
if (!opt->len || opt->len > NMRP_MAX_OPT_SIZE) {
break;
}
@ -243,6 +222,10 @@ static void *msg_opt_data(struct nmrp_msg *msg, uint16_t type, uint16_t *len)
return buf;
}
if (!opt->len) {
break;
}
remaining -= opt->len;
opt = NMRP_OPT_NEXT(opt);
}