From patchwork Sat Apr 15 13:58:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 751039 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3w4x3M0Zwzz9s7k for ; Sat, 15 Apr 2017 23:59:26 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 1B79DC21C60; Sat, 15 Apr 2017 13:59:21 +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, RCVD_IN_MSPIKE_H2 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 027B9C21C45; Sat, 15 Apr 2017 13:59:19 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 02A40C21C45; Sat, 15 Apr 2017 13:59:17 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lists.denx.de (Postfix) with ESMTPS id A4872C21C3F for ; Sat, 15 Apr 2017 13:59:17 +0000 (UTC) Received: from LT002.fritz.box ([95.222.184.236]) by mail.gmx.com (mrgmx002 [212.227.17.190]) with ESMTPSA (Nemesis) id 0LlESk-1cQsE00FHi-00b1hP; Sat, 15 Apr 2017 15:59:06 +0200 From: Heinrich Schuchardt To: Simon Glass Date: Sat, 15 Apr 2017 15:58:55 +0200 Message-Id: <20170415135855.26984-1-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.11.0 X-Provags-ID: V03:K0:npEDdQPvEpbdb0uS9MLaAdJrnmsMqZkp0EO61+yknteg+KhDlpz vJDZkPBJ13mgxZUH3HrT6w26Rxq09B6RRKvrXeZmIY0t6sQV/6q698Efi/xGWk0DdQskamg euJeUPMxUdo0KqSUC673XtkvuXMm+uqhGLF/ZXzwztCcUDmW/jLdBpOfZ81atW9r2PfGnIz UynEPkGPJt6npM24QW3Fw== X-UI-Out-Filterresults: notjunk:1; V01:K0:3XmikTAGalY=:D5oDJi4QTXhNydachB6hSj ruE/w5dDdv/wrJRGt+mk3guk4jUdT58NR3BZ118Q1wur2eLMfXyncbHe2kWp2IhpU9vyTf2aC UlxBdp6e7AStuMnzZdwj3zRzzs3/pwEgD6Uyy2Osp1Hm5VLKnAjNVeq5qfR4NoryqFOZ9a0rB RVKWjZC9p8LlKqOAmJNqaHenw0PdV8aT2KYd++Oh2lZY4rwdegzHSF+8o8o545bZMbiCmH+F+ Zf9fgaSvgsEv0htYrTvLOOZ2/71CIdP6GpIQXrDZ1mFOKD77zPwdjWMGMyL4BS4+rMogFXHwm 8ygbFGOWenl9TsJ5FInXYHH/wv8uE6zK8L76mo8sGIrvOJcjhPVpnct0NExUyWhmPuLiag7zd NjWDOD78xIhuEF2iovu33oQh+ZQAppZg6ZMlaptohqM4Ll2PI9BHx2ur5KUroz0SNRq94s/Y4 VeKBCTJ2CFsyUrHbhH/N+FwguYxk2ECUZU6sJD52Gs1vA/DR6GUw8XPIgjFJkonHmCfgyuL1K fSq9pqVjPK9Q7SGwkC1NBYfmWVVXkLhewkbuUbL6bbSNgIsLrWCXiDg2IGQo7Y+pyuLbtpi6X HfK6vf0I0VT6vfGlC7SuMIVl08OlMASfdeJW8H5mYAXcv8uJJ+qtuJfzeOR9lmai058NjHQFh mMJ5QfDbZxtxYHc700xY/rW+thzWzcJGW5945S3gCjivEWoEQI6bXrbhvmX/GGxCTOew5akyP vg6dHg6kJUR0IoIhtflBtn21AukWuP0yVNkRjK/f6ieXHZ+jdecnCOCFiNM= Cc: u-boot@lists.denx.de, Andy Shevchenko , Heinrich Schuchardt Subject: [U-Boot] [PATCH] x86: zImage: avoid potential NULL dereference 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" If bootargs is not assigned getenv("bootargs") will return NULL. Some part of the code is checking for this condition. Other parts dereference a possible NULL pointer. The problem was indicated by cppcheck. Signed-off-by: Heinrich Schuchardt --- arch/x86/lib/zimage.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c index aafbeb01f9..9b564340a6 100644 --- a/arch/x86/lib/zimage.c +++ b/arch/x86/lib/zimage.c @@ -48,12 +48,14 @@ static void build_command_line(char *command_line, int auto_boot) command_line[0] = '\0'; - env_command_line = getenv("bootargs"); + env_command_line = getenv("bootargs"); + + if (!env_command_line) + env_command_line = ""; /* set console= argument if we use a serial console */ if (!strstr(env_command_line, "console=")) { if (!strcmp(getenv("stdout"), "serial")) { - /* We seem to use serial console */ sprintf(command_line, "console=ttyS0,%s ", getenv("baudrate")); @@ -63,8 +65,7 @@ static void build_command_line(char *command_line, int auto_boot) if (auto_boot) strcat(command_line, "auto "); - if (env_command_line) - strcat(command_line, env_command_line); + strcat(command_line, env_command_line); printf("Kernel command line: \"%s\"\n", command_line); }