In the current net stack, we have a few functions to get and set
the "ethaddr" and "ethNaddr" environment variables, which use magic
values to get and set these environment variables. Remove the magicness
of the buffer by defining it proper and also check the input for its
length.

Additionally use the define in fdt parser where the ethaddr variables
are also used.

Signed-off-by: Olliver Schinagl <oli...@schinagl.nl>
---
 common/fdt_support.c |  2 +-
 include/net.h        |  1 +
 net/eth_common.c     | 14 +++++++++-----
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/common/fdt_support.c b/common/fdt_support.c
index c6a76b7ad2..d462bf0642 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -471,7 +471,7 @@ void fdt_fixup_ethernet(void *fdt)
 {
        int i, j, prop;
        char *tmp, *end;
-       char mac[16];
+       char mac[ETH_ENETADDR_ENV_NAME_LEN];
        const char *path;
        unsigned char mac_addr[ARP_HLEN];
        int offset;
diff --git a/include/net.h b/include/net.h
index c703c62c99..ad2a8a3678 100644
--- a/include/net.h
+++ b/include/net.h
@@ -243,6 +243,7 @@ void eth_set_current(void);         /* set nterface to 
ethcur var */
 
 int eth_get_dev_index(void);           /* get the device index */
 void eth_parse_enetaddr(const char *addr, uchar *enetaddr);
+#define ETH_ENETADDR_ENV_NAME_LEN 32
 int eth_getenv_enetaddr(const char *name, uchar *enetaddr);
 int eth_setenv_enetaddr(const char *name, const uchar *enetaddr);
 
diff --git a/net/eth_common.c b/net/eth_common.c
index 049c1ee6f9..0fe4d260d8 100644
--- a/net/eth_common.c
+++ b/net/eth_common.c
@@ -45,16 +45,20 @@ int eth_setenv_enetaddr(const char *name, const uchar 
*enetaddr)
 int eth_getenv_enetaddr_by_index(const char *base_name, int index,
                                 uchar *enetaddr)
 {
-       char enetvar[32];
-       sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
+       char enetvar[ETH_ENETADDR_ENV_NAME_LEN];
+
+       snprintf(enetvar, ETH_ENETADDR_ENV_NAME_LEN,
+                index ? "%s%daddr" : "%saddr", base_name, index);
        return eth_getenv_enetaddr(enetvar, enetaddr);
 }
 
 int eth_setenv_enetaddr_by_index(const char *base_name, int index,
                                 uchar *enetaddr)
 {
-       char enetvar[32];
-       sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
+       char enetvar[ETH_ENETADDR_ENV_NAME_LEN];
+
+       snprintf(enetvar, ETH_ENETADDR_ENV_NAME_LEN,
+                index ? "%s%daddr" : "%saddr", base_name, index);
        return eth_setenv_enetaddr(enetvar, enetaddr);
 }
 
@@ -72,7 +76,7 @@ void eth_common_init(void)
 
 int eth_mac_skip(int index)
 {
-       char enetvar[15];
+       char enetvar[ETH_ENETADDR_ENV_NAME_LEN];
        char *skip_state;
 
        sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
-- 
2.11.0

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to