diff --git a/ethsock.c b/ethsock.c index c1674d4..0372b59 100644 --- a/ethsock.c +++ b/ethsock.c @@ -21,11 +21,6 @@ #endif #endif -#ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif - - struct ethsock { const char *intf; diff --git a/nmrp.c b/nmrp.c index ff4aeb7..a374c6c 100644 --- a/nmrp.c +++ b/nmrp.c @@ -213,16 +213,20 @@ static int msg_ntoh(struct nmrp_msg *msg) static void *msg_opt_data(struct nmrp_msg *msg, int type, uint16_t *len) { + static char buf[128]; struct nmrp_opt *opt = msg->opts; int remaining = msg->len - NMRP_HDR_LEN; + memset(buf, 0, sizeof(buf)); + while (remaining > 0) { if (opt->type == type) { if (opt->len == NMRP_OPT_LEN) { return NULL; } *len = opt->len - NMRP_OPT_LEN; - return (char*)&opt->val; + memcpy(buf, &opt->val, MIN(*len, sizeof(buf)-1)); + return buf; } remaining -= opt->len; diff --git a/nmrpd.h b/nmrpd.h index 0eabf26..cf5138d 100644 --- a/nmrpd.h +++ b/nmrpd.h @@ -49,6 +49,10 @@ #include #endif +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + enum nmrp_op { NMRP_UPLOAD_FW = 0, NMRP_UPLOAD_ST = 1,