From patchwork Tue Sep 26 18:08:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rini X-Patchwork-Id: 818764 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3y1ptq2FDFz9t3x for ; Wed, 27 Sep 2017 04:11:47 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0954FC21F70; Tue, 26 Sep 2017 18:09:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4A50AC21E08; Tue, 26 Sep 2017 18:09:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 38333C21F5E; Tue, 26 Sep 2017 18:08:34 +0000 (UTC) Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by lists.denx.de (Postfix) with ESMTPS id 8437FC21F03 for ; Tue, 26 Sep 2017 18:08:30 +0000 (UTC) Received: by mail-qt0-f195.google.com with SMTP id b1so7547113qtc.0 for ; Tue, 26 Sep 2017 11:08:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6XZuE5jYKTNjeDTWlpll3+I8tbfBIU7Az5yKsImVq/o=; b=NlpPHda4mIqveHx3qRmyBgl1Jd2rOlykf+q475UVWwyezOO/bqhw6nDJtmg8yo0oLU fbBYGp0vhFRKVGyb6KE8TdOEiVgoIX024ZLq0Pck8/RmHlouB+7CI6VLsZO1lufvYQ17 M5xEsC8N4ceBEK0UuOVB6XvYNh4I3Dddw9J4mRIAMll61ouXPmzGEtgam1HWj/Be2/F3 ogRk34IRTtDvvlAWGQi3ML8xPxtQqRRYb+agIwwKLX/nddrYCeElqLV1r7yuwpINI3yK e0Ikld9cmWbJQzEsLZLLUbXj/WI6qOE9pVVn6Jmd2KkfGBGy7Fue3zpApZ/ByCYUeE0y hAzg== X-Gm-Message-State: AHPjjUjLBWhWwzWaLJKUDUbd582kJnsBH/QlczBVjoWKEr9tFeK5L6GJ FSqZ2vrekoO7hh+4LzTtR6EO X-Google-Smtp-Source: AOwi7QA0Foito0s8Qd0fstd50fcE6qN5y1zNoUWeS4k6cQxaNJEGyHB4Lc/vDFQ+BFYykBa15K//SA== X-Received: by 10.200.52.232 with SMTP id x37mr17315155qtb.85.1506449309221; Tue, 26 Sep 2017 11:08:29 -0700 (PDT) Received: from localhost.localdomain (cpe-65-184-142-68.ec.res.rr.com. [65.184.142.68]) by smtp.gmail.com with ESMTPSA id z192sm6994513qka.91.2017.09.26.11.08.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Sep 2017 11:08:28 -0700 (PDT) From: Tom Rini To: u-boot@lists.denx.de Date: Tue, 26 Sep 2017 14:08:30 -0400 Message-Id: <1506449310-19066-1-git-send-email-trini@konsulko.com> X-Mailer: git-send-email 1.9.1 Cc: Joe Hershberger Subject: [U-Boot] [PATCH] test/dm: Fix string handling issues in the eth test X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Coverity scan has identified potential buffer overruns in these tests. Correct this by zeroing our buffer and using strncpy not strcpy. Reported-by: Coverity (CID: 155462, 155463) Cc: Joe Hershberger Cc: Simon Glass Cc: Bin Meng Signed-off-by: Tom Rini Reviewed-by: Simon Glass Reviewed-by: Joe Hershberger --- test/dm/eth.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/dm/eth.c b/test/dm/eth.c index 122fab924d6a..67fd660ee4f5 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -110,6 +110,7 @@ static int dm_test_eth_act(struct unit_test_state *uts) char ethaddr[DM_TEST_ETH_NUM][18]; int i; + memset(ethaddr, '\0', sizeof(ethaddr)); net_ping_ip = string_to_ip("1.1.2.2"); /* Prepare the test scenario */ @@ -119,7 +120,7 @@ static int dm_test_eth_act(struct unit_test_state *uts) ut_assertok(device_remove(dev[i], DM_REMOVE_NORMAL)); /* Invalidate MAC address */ - strcpy(ethaddr[i], env_get(addrname[i])); + strncpy(ethaddr[i], env_get(addrname[i]), 17); /* Must disable access protection for ethaddr before clearing */ env_set(".flags", addrname[i]); env_set(addrname[i], NULL); @@ -187,7 +188,8 @@ static int dm_test_eth_rotate(struct unit_test_state *uts) net_ping_ip = string_to_ip("1.1.2.2"); /* Invalidate eth1's MAC address */ - strcpy(ethaddr, env_get("eth1addr")); + memset(ethaddr, '\0', sizeof(ethaddr)); + strncpy(ethaddr, env_get("eth1addr"), 17); /* Must disable access protection for eth1addr before clearing */ env_set(".flags", "eth1addr"); env_set("eth1addr", NULL); @@ -200,7 +202,7 @@ static int dm_test_eth_rotate(struct unit_test_state *uts) if (!retval) { /* Invalidate eth0's MAC address */ - strcpy(ethaddr, env_get("ethaddr")); + strncpy(ethaddr, env_get("ethaddr"), 17); /* Must disable access protection for ethaddr before clearing */ env_set(".flags", "ethaddr"); env_set("ethaddr", NULL);