From patchwork Wed Oct 11 19:34:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Rini X-Patchwork-Id: 824527 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 3yC41k6KmHz9t2V for ; Thu, 12 Oct 2017 06:34:49 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 38608C21EB1; Wed, 11 Oct 2017 19:34:44 +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_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 8790DC21D92; Wed, 11 Oct 2017 19:34:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6E255C21D92; Wed, 11 Oct 2017 19:34:40 +0000 (UTC) Received: from mail-qt0-f193.google.com (mail-qt0-f193.google.com [209.85.216.193]) by lists.denx.de (Postfix) with ESMTPS id 6362DC21D6A for ; Wed, 11 Oct 2017 19:34:38 +0000 (UTC) Received: by mail-qt0-f193.google.com with SMTP id x54so3771648qth.0 for ; Wed, 11 Oct 2017 12:34:38 -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:subject:date:message-id; bh=GtXnbobZ7V1c9P8fYiQMKJd3Dsm/eaNKKvserpxnmAg=; b=E7yboP0oJB5DCyExCy+yl4Q3WCs59LEwH1eM6Uq7He1sas+r2LDOVyZLGrwrke30JA wqaxqYRYabPeCfj3mkjqxMU93OFdXRKP/Fi95L9vhCGBOiq68IvL/qT6LW2TyRr3Pyh3 kof1Ou6S3m0pqRrwQjhtCZ9rsQu5tWdBK12F2sJe+QyMmmske6eRQrtjg95dGR0LjYSV WsHTAow+ot2mZfidLDOF/e1ODX+U9+RXnzR2CVGW0SI3WWub3FL1UwOJXxry+zy2v19d TDn9NOUQu4SATxlQavIiW1CqhUF0VV7TjagXWZtOVuUHqIq4rlB32GkHsxfcMDZNjP7a /trw== X-Gm-Message-State: AMCzsaX315fyjrU68f4VFsQPZdZ8GPCiqAAYJGbVDzb4Kq8j7uHoZ0G7 ifusGbDADDZC67FnHTruvEqB X-Google-Smtp-Source: AOwi7QAOhXOZNzZ9+35hCKNI9p4es9fYGnrc2xU8ihuXhs7orRXMftzx/eIbCvQq1QITRvTlYQhT6A== X-Received: by 10.13.230.15 with SMTP id p15mr429978ywe.98.1507750476944; Wed, 11 Oct 2017 12:34:36 -0700 (PDT) Received: from localhost.localdomain ([2606:a000:1401:811b:8c0b:3f31:3238:e1b8]) by smtp.gmail.com with ESMTPSA id z126sm5496775ywe.91.2017.10.11.12.34.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Oct 2017 12:34:36 -0700 (PDT) From: Tom Rini To: u-boot@lists.denx.de Date: Wed, 11 Oct 2017 15:34:33 -0400 Message-Id: <1507750473-10998-1-git-send-email-trini@konsulko.com> X-Mailer: git-send-email 2.7.4 Subject: [U-Boot] [PATCH] cmd/pxe.c: Rework bootargs construction to clarify string checks 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" As the code currently stands, we first check that the length of the given command line, along with ip_str/mac_str along with an additional 1 for the NULL termination will fit within the buffer we have, and if not, we return an error. The way this code was originally written however left Coverity "unhappy" due to using strcat rather than strncat. Switching this to strncat however causes clang to be unhappy that we aren't enforcing the "1" portion within strncat. Rather than further re-work the code to include a "- 1" in this case as well, make the strcat code only be done within the else side of the length test. This keeps both clang and Coverity happy. Fixes: 48ee0a87bc46 ("cmd/pxe.c: Rework initrd and bootargs handling slightly") Signed-off-by: Tom Rini --- cmd/pxe.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/pxe.c b/cmd/pxe.c index a62cbe192a32..7043ad11fdd8 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -686,16 +686,17 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label) strlen(ip_str), strlen(mac_str), sizeof(bootargs)); return 1; + } else { + if (label->append) + strncpy(bootargs, label->append, + sizeof(bootargs)); + strcat(bootargs, ip_str); + strcat(bootargs, mac_str); + + cli_simple_process_macros(bootargs, finalbootargs); + env_set("bootargs", finalbootargs); + printf("append: %s\n", finalbootargs); } - - if (label->append) - strncpy(bootargs, label->append, sizeof(bootargs)); - strncat(bootargs, ip_str, sizeof(bootargs) - strlen(bootargs)); - strncat(bootargs, mac_str, sizeof(bootargs) - strlen(bootargs)); - - cli_simple_process_macros(bootargs, finalbootargs); - env_set("bootargs", finalbootargs); - printf("append: %s\n", finalbootargs); } bootm_argv[1] = env_get("kernel_addr_r");