Don't break if using the client-supplied filename
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sun, 14 Feb 2016 22:01:58 +0000 (23:01 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sun, 14 Feb 2016 22:01:58 +0000 (23:01 +0100)
ethsock.c
nmrp.c
nmrpd.h

index c1674d44cc779982a3dec7c771e275ba3b02a648..0372b5925e64f674596ab700adb7402aa09ff5b4 100644 (file)
--- a/ethsock.c
+++ b/ethsock.c
 #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 ff4aeb7ac430ece23ed7d00c04615365fb879c20..a374c6cc6d89c4115b88cf287b3c64ea26528bb5 100644 (file)
--- 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 0eabf26e7cdfed96b45fe3965ebdf6905669b9cd..cf5138df8ebdf6e08ece73ffaf36212be7412261 100644 (file)
--- a/nmrpd.h
+++ b/nmrpd.h
 #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,