From patchwork Tue Jul 25 21:16:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Long Li X-Patchwork-Id: 129701 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B496442F47; Tue, 25 Jul 2023 23:17:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A69B843261; Tue, 25 Jul 2023 23:17:08 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id A93684325D for ; Tue, 25 Jul 2023 23:17:07 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1004) id 0E7C02380B11; Tue, 25 Jul 2023 14:17:07 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0E7C02380B11 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxonhyperv.com; s=default; t=1690319827; bh=2No1UIXb6tyLo4FDyvbBKUAtmvqVQxownJflSVPupzk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LF56xjeOQFMt+26jBsDbpomiy4Z3Df6GhoI5fGGJSXgvEszI47ANKc8OwMATDCDkr sC9wYygaP8Pr+oLwS/wt/yB4J8ggkciLW/P6CnHSQHMdEXXsgGWe5zjw5HOvUeaJB1 bqCz6I77n50nrs2OqZ0ny4Sdp949D/TUZs89tfSw= From: longli@linuxonhyperv.com To: Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org, Ajay Sharma , Long Li Subject: [PATCH] net/mana: use %m for fscanf to read mac address Date: Tue, 25 Jul 2023 14:16:55 -0700 Message-Id: <1690319815-28594-2-git-send-email-longli@linuxonhyperv.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1690319815-28594-1-git-send-email-longli@linuxonhyperv.com> References: <1690319815-28594-1-git-send-email-longli@linuxonhyperv.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Long Li 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 Acked-by: Ferruh Yigit --- drivers/net/mana/mana.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/mana/mana.c b/drivers/net/mana/mana.c index f1fdcf426a..28d8f5b23e 100644 --- a/drivers/net/mana/mana.c +++ b/drivers/net/mana/mana.c @@ -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; } }