ether_aton() and ether_ntoa() use static buffers which are overwritten by next call of this function so those functions should not be used in multithread environment. Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx> --- include/usbg/usbg.h | 1 + src/usbg.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index a44203a..e123365 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -38,6 +38,7 @@ #define LANG_US_ENG 0x0409 #define DEFAULT_CONFIG_LABEL "config" +/* This one has to be at least 18 bytes to hold network addres */ #define USBG_MAX_STR_LENGTH 256 #define USBG_MAX_PATH_LENGTH PATH_MAX #define USBG_MAX_NAME_LENGTH 40 diff --git a/src/usbg.c b/src/usbg.c index 9e71067..b17a707 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -744,6 +744,7 @@ static int usbg_parse_function_net_attrs(usbg_function *f, usbg_function_attrs *f_attrs) { struct ether_addr *addr; + struct ether_addr addr_buf; char str_addr[USBG_MAX_STR_LENGTH]; int ret; @@ -751,7 +752,7 @@ static int usbg_parse_function_net_attrs(usbg_function *f, if (ret != USBG_SUCCESS) goto out; - addr = ether_aton(str_addr); + addr = ether_aton_r(str_addr, &addr_buf); if (addr) { f_attrs->net.dev_addr = *addr; } else { @@ -763,7 +764,7 @@ static int usbg_parse_function_net_attrs(usbg_function *f, if (ret != USBG_SUCCESS) goto out; - addr = ether_aton(str_addr); + addr = ether_aton_r(str_addr, &addr_buf); if (addr) { f_attrs->net.host_addr = *addr; } else { @@ -2314,6 +2315,7 @@ int usbg_get_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs) int usbg_set_function_net_attrs(usbg_function *f, usbg_f_net_attrs *attrs) { int ret = USBG_SUCCESS; + char addr_buf[USBG_MAX_STR_LENGTH]; char *addr; /* ifname is read only so we accept only empty string for this param */ @@ -2322,12 +2324,12 @@ int usbg_set_function_net_attrs(usbg_function *f, usbg_f_net_attrs *attrs) goto out; } - addr = ether_ntoa(&attrs->dev_addr); + addr = ether_ntoa_r(&attrs->dev_addr, addr_buf); ret = usbg_write_string(f->path, f->name, "dev_addr", addr); if (ret != USBG_SUCCESS) goto out; - addr = ether_ntoa(&attrs->host_addr); + addr = ether_ntoa_r(&attrs->host_addr, addr_buf); ret = usbg_write_string(f->path, f->name, "host_addr", addr); if (ret != USBG_SUCCESS) goto out; @@ -2385,7 +2387,8 @@ int usbg_set_net_dev_addr(usbg_function *f, struct ether_addr *dev_addr) int ret = USBG_SUCCESS; if (f && dev_addr) { - char *str_addr = ether_ntoa(dev_addr); + char str_buf[USBG_MAX_STR_LENGTH]; + char *str_addr = ether_ntoa_r(dev_addr, str_buf); ret = usbg_write_string(f->path, f->name, "dev_addr", str_addr); } else { ret = USBG_ERROR_INVALID_PARAM; @@ -2399,7 +2402,8 @@ int usbg_set_net_host_addr(usbg_function *f, struct ether_addr *host_addr) int ret = USBG_SUCCESS; if (f && host_addr) { - char *str_addr = ether_ntoa(host_addr); + char str_buf[USBG_MAX_STR_LENGTH]; + char *str_addr = ether_ntoa_r(host_addr, str_buf); ret = usbg_write_string(f->path, f->name, "host_addr", str_addr); } else { ret = USBG_ERROR_INVALID_PARAM; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html