Don't break if using the client-supplied filename

This commit is contained in:
Joseph C. Lehner 2016-02-14 23:01:58 +01:00
parent 23f1eb2469
commit bc43f07291
3 changed files with 9 additions and 6 deletions

View file

@ -21,11 +21,6 @@
#endif
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
struct ethsock
{
const char *intf;

6
nmrp.c
View file

@ -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;

View file

@ -49,6 +49,10 @@
#include <windows.h>
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
enum nmrp_op {
NMRP_UPLOAD_FW = 0,
NMRP_UPLOAD_ST = 1,