From patchwork Mon Aug 20 00:00:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 959472 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ew0d88Oc"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41tvPZ1Zv0z9s4c for ; Mon, 20 Aug 2018 10:12:02 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E1CC8C21E08; Mon, 20 Aug 2018 00:10:51 +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=FREEMAIL_FROM, KHOP_BIG_TO_CC, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID 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 E6423C21E7D; Mon, 20 Aug 2018 00:07:50 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D21DAC21C93; Mon, 20 Aug 2018 00:05:07 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by lists.denx.de (Postfix) with ESMTPS id 87D5EC21C2C for ; Mon, 20 Aug 2018 00:05:07 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id s9-v6so12466423wmh.3 for ; Sun, 19 Aug 2018 17:05:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ROtOQZiuunBS9vPCve3JPg6l+vyOXnXN5uJ6rvSmfYw=; b=ew0d88Oc0cQpNUFL2bhIg6xfIi+x8IfZbwk5rUsFshOU4zyRuMfy9I0eRDe0a87Cvh 3kJ+oAnCvJExEhv2TXJ9xhIfmlx9Xit6nNuCK9am65OXz3KwZ16EfeRV2XwNp4ViybEP Sm5W7aslbZbxKLt5IdREFBGpg/QJVYxytQKoYQ/Vcr0M1Py721xPguwHFrxjekrrFo3a jNuPD3B5KJjYE0jwKP2e0tAFDXPO3espwcv0BRh/a3Z7PlL6tNpsm6kMDWHXAIRwq3Ih eZyRCIX7PZBqqmsmYwMd6QF9HNyhoyMlLFiVblGwOBl1tBWPNKsCFdqdA0rfVi+VTySG N9Xw== 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:in-reply-to :references; bh=ROtOQZiuunBS9vPCve3JPg6l+vyOXnXN5uJ6rvSmfYw=; b=KAJHJqu6jFjwSoXIhRcJbNq2wGjobnmtD4zqi/smCdqXxof1AoxsaDgDhwWvggGXPJ cdvRcBucStkgArHQ+7ipaRg4mvwlPIl1EIkN2YqVbkceg7Wctphkkb+5FRe4G2KTy4rb MG7qzD0EmuvDCbhXdEJbM9Da5rqyszQLqX0VwWfuzJMDnZCeN9EA5RlXGqeOsSOsAW4y ZYFa5nviNnfrseY2/1fwklE8FFi0dEqCVtxuIWVAbt8VBb1A2Sy7B0SAr5kR1u+l/MfM iHAt+hN27OXrFiobQmqj589FS0NKle1MDAk2NJmmkbRuhPWjprgyp2fhGwUcSqGP6LOc rL3A== X-Gm-Message-State: AOUpUlFPgtn4aQFSSqQvoRUXhy6Ax6di1dvjKe0PB0MaQPdRemMeinxM tW1NCcVjD7Lw2jU629YNCm0= X-Google-Smtp-Source: AA+uWPz20Jj+nX6jiJDfndzvrYfL3/ih0qBn/L7vkfsJyAEJZSic1SpGpKIHm9uQiw+M7UdZpDFFqg== X-Received: by 2002:a1c:1252:: with SMTP id 79-v6mr23412307wms.70.1534723507259; Sun, 19 Aug 2018 17:05:07 -0700 (PDT) Received: from localhost.localdomain (ipb218f552.dynamic.kabel-deutschland.de. [178.24.245.82]) by smtp.gmail.com with ESMTPSA id w4-v6sm7648194wro.24.2018.08.19.17.05.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 19 Aug 2018 17:05:06 -0700 (PDT) From: Eugeniu Rosca X-Google-Original-From: Eugeniu Rosca To: Tom Rini , Simon Glass , Masahiro Yamada , Andrey Ryabinin , Andre Przywara , Igor Opaniuk , Rasmus Villemoes , Bryan O'Donoghue , Andy Shevchenko , Chris Packham , Alex Kiernan , Alexey Brodkin , Michal Simek , York Sun , "Derald D . Woods" , Miquel Raynal , Baruch Siach , Albert Aribaud , Stephen Warren , Alexander Graf , Rick Chen , Adam Ford , Simon Goldschmidt , Pantelis Antoniou , Marek Vasut , Takeshi Kihara , Bin Meng , Heinrich Schuchardt , Anatolij Gustschin , Jean-Jacques Hiblot , Jaehoon Chung , Peng Fan , Andy Yan , Philipp Tomsich , Nobuhiro Iwamatsu , Mario Six , Grygorii Strashko , Neil Armstrong , Joe Hershberger , Florian Fainelli , Stefan Roese , Zubair Lutfullah Kakakhel , Quentin Schulz Date: Mon, 20 Aug 2018 02:00:32 +0200 Message-Id: <20180820000033.25519-9-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180820000033.25519-1-erosca@de.adit-jv.com> References: <20180820000033.25519-1-erosca@de.adit-jv.com> X-Mailman-Approved-At: Mon, 20 Aug 2018 00:07:41 +0000 Cc: u-boot@lists.denx.de, Eugeniu Rosca Subject: [U-Boot] [PATCH 8/8] hashtable: Fix zero-sized array undefined behavior 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" Enabling CONFIG_UBSAN=y, below runtime warning occurs both in sandbox and R-Car H3 Salvator-X U-Boot: Reviewed-by: Tom Rini ===================================================================== UBSAN: Undefined behaviour in lib/hashtable.c:784:8 variable length array bound value 0 <= 0 ===================================================================== It has a slightly different wording when compiling sandbox U-Boot with "gcc-8 -fsanitize=undefined -lubsan": -----8<----- lib/hashtable.c:784:8: runtime error: \ variable length array bound evaluates to non-positive value 0 -----8<----- Fix the error by making sure that localvars[] can't take a negative or zero size. Fixes: d5370febbcbc ("env: delete selected vars not present in imported env") Signed-off-by: Eugeniu Rosca --- include/search.h | 2 +- lib/hashtable.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/search.h b/include/search.h index 5d07b49073cc..417dacdb4482 100644 --- a/include/search.h +++ b/include/search.h @@ -99,7 +99,7 @@ extern ssize_t hexport_r(struct hsearch_data *__htab, */ extern int himport_r(struct hsearch_data *__htab, const char *__env, size_t __size, const char __sep, - int __flag, int __crlf_is_lf, int nvars, + int __flag, int __crlf_is_lf, unsigned int nvars, char * const vars[]); /* Walk the whole table calling the callback on each element */ diff --git a/lib/hashtable.c b/lib/hashtable.c index 1c48692b69ed..f35d2022f630 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -778,10 +778,10 @@ static int drop_var_from_set(const char *name, int nvars, char * vars[]) int himport_r(struct hsearch_data *htab, const char *env, size_t size, const char sep, int flag, - int crlf_is_lf, int nvars, char * const vars[]) + int crlf_is_lf, unsigned int nvars, char * const vars[]) { char *data, *sp, *dp, *name, *value; - char *localvars[nvars]; + char *localvars[nvars + 1]; int i; /* Test for correct arguments. */