net/mana: use %m for fscanf to read mac address
Checks
Commit Message
From: Long Li <longli@microsoft.com>
Use %m through fscanf to allocate mac dynamically is safer than using
mac[20], this guarantees there is no overflow on mac[].
Signed-off-by: Long Li <longli@microsoft.com>
---
drivers/net/mana/mana.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Comments
On 7/25/2023 10:16 PM, longli@linuxonhyperv.com wrote:
> From: Long Li <longli@microsoft.com>
>
> Use %m through fscanf to allocate mac dynamically is safer than using
> mac[20], this guarantees there is no overflow on mac[].
>
> Signed-off-by: Long Li <longli@microsoft.com>
>
Acked-by: Ferruh Yigit <ferruh.yigit@amd.com>
Applied to dpdk-next-net/main, thanks.
@@ -914,7 +914,6 @@ get_port_mac(struct ibv_device *device, unsigned int port,
DIR *dir;
struct dirent *dent;
unsigned int dev_port;
- char mac[20];
MANA_MKSTR(path, "%s/device/net", device->ibdev_path);
@@ -924,6 +923,7 @@ get_port_mac(struct ibv_device *device, unsigned int port,
while ((dent = readdir(dir))) {
char *name = dent->d_name;
+ char *mac = NULL;
MANA_MKSTR(port_path, "%s/%s/dev_port", path, name);
@@ -951,7 +951,7 @@ get_port_mac(struct ibv_device *device, unsigned int port,
if (!file)
continue;
- ret = fscanf(file, "%s", mac);
+ ret = fscanf(file, "%ms", &mac);
fclose(file);
if (ret < 0)
@@ -960,6 +960,8 @@ get_port_mac(struct ibv_device *device, unsigned int port,
ret = rte_ether_unformat_addr(mac, addr);
if (ret)
DRV_LOG(ERR, "unrecognized mac addr %s", mac);
+
+ free(mac);
break;
}
}