From patchwork Mon May 30 06:03:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1636789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=mkvnEkQf; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::639; helo=mail-pl1-x639.google.com; envelope-from=swupdate+bncbcwivbv7sugrbjv42gkamgqelmt5qbq@googlegroups.com; receiver=) Received: from mail-pl1-x639.google.com (mail-pl1-x639.google.com [IPv6:2607:f8b0:4864:20::639]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LBPwS6ZPlz9s0w for ; Mon, 30 May 2022 16:03:20 +1000 (AEST) Received: by mail-pl1-x639.google.com with SMTP id n8-20020a170902d2c800b00161ffe6804esf6721078plc.21 for ; Sun, 29 May 2022 23:03:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1653890598; cv=pass; d=google.com; s=arc-20160816; b=T3LebMc++Qf11jGey/6bpC0KqvM0Ie45354sN3r256pMAKeS8HssDSWH/ue4TNM2jf JhBP+/kB2riFObO6JXTnklCAQHDoZHyBSuGPDUbizW+/6pNtRn3Ae3Ar+iQpZQGVHRqo kO1dIF2z8uBohgnBCE68t2MjZrMfXDoIs9CKLPEZHJ9QjEjoIqLPtow2EFGqNKv3LMnl IVQyq9gXJqERaMxl4t2l59nVDkkkRIMsXstguCes+0b3f2FR3ipo/76y2+t6zUpE4bNo TYXnwiAa9zBEXPoYQKF6bvgiYibLDw84k96kf+TLOJ7jps5ClgpNkv7/t26ZHLFxtj2j ThCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=hDS8FGEahx/sZNg4iWpiUsSOaWftRJuQDnxl5yVqNP8=; b=vIz7yqO7Np8OXFv9lV8NZNdtlSfpfQHHdam2a9oD9DOyQEsAthWK9svbLNEWirfrDi tbAHswnHfOsoZPBhRupP7aj2z/to1T3WS+SQ7dZzz09GvK1nARwD/5xD/2W0GYCrSsCL nyQHne2skKVgpdwc6mbqOfkxT0VNMAqXPgl75JaEWMgKSjbg8/CdJq1dbXGyssLZlpPV vf6dWeG93lU/wOjkRsz68s9fX7jmJRXgmkJuNQ8G82VNPbSLfE50N+V/mkLb32xOA6GN YXK+CUU/+c4qN84YZpusQQCfnewRagZIFg+ZNtRnSued10v2sw++B/efD4FcN9k6Bprx m24A== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=hDS8FGEahx/sZNg4iWpiUsSOaWftRJuQDnxl5yVqNP8=; b=mkvnEkQf0WM6yYmPp+l9FrnYnImEu7GGYqsfk/9D8KXJ5LLYQ3lB8qLlItbcJ4UfGG N9O93oKiYgRLmvcC5e0/bJXWf/bbdt9QCGzHJ4GozaDjJc/W2gnjCVtVNINvGkp2rIXU CaTH6mwedPVB4Gw5P0Jc304CIGu7d9umpKdPXYGnD9q1V0jpH/5KxHj6zvV2msT304es AzvG5x6Ctrjmio8/qvwpcgMVKcKw1Zh2dAJZhqmE2stTXMAoXpIeLpnIAeqyRweujg92 r8HZoJ+rDMGBvx6RPrO+o5Ufn45/xtjWvKW4XPeRKTb8KVTRYo0m9Zbjg5ng/AAoebQD OpLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=hDS8FGEahx/sZNg4iWpiUsSOaWftRJuQDnxl5yVqNP8=; b=uK8Y2i16W24FbalpINGIVG0naGMuh1vn74/BwbM7LqxF6SCbz4gDXLikCzZ6uP7H8O 4jVD6X0CNZVS5cPZhSIbIugeI2jc4yRs8vlBjPattd7w6zcm8gswfQdbQoOs4hIm2RgK m874LcI2cjP5j//LSaqsWUgxsVMX+WvIMlpxhOVQ1gKz/sZrryx6br33UoVlZopW6ds9 aoSoyVmJnlUv4V2+RSTlP3/T1jn2unISW/ZuoV3nTGApGjjkIURS2WBvqpu1/d5yRDKp nney8kQ2Kbb0Fzs3t1JPFfUL93BipBTjtv9+dQDa4CFCJfNZFU9y2vd+r+JbvvusVypN 4/Bg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM533ZF59aZvBgLhz/sfaqIsXx9R58SNTJnV3X7Xcro/rkbKk0OTkU UN7V1RKavrLThlV2pDbX9Ls= X-Google-Smtp-Source: ABdhPJyaNPtH0s7KXMhjNMQibbhb5ye2RKE7UBOzPV7WZifSosxSCWzNts2Son1VB9XiCNH5bB7zeQ== X-Received: by 2002:a17:90a:77c5:b0:1df:dc04:526e with SMTP id e5-20020a17090a77c500b001dfdc04526emr21432557pjs.225.1653890598326; Sun, 29 May 2022 23:03:18 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a65:6e8c:0:b0:381:309f:14a0 with SMTP id bm12-20020a656e8c000000b00381309f14a0ls11861014pgb.2.gmail; Sun, 29 May 2022 23:03:17 -0700 (PDT) X-Received: by 2002:a63:884a:0:b0:3fa:ad94:9408 with SMTP id l71-20020a63884a000000b003faad949408mr25583209pgd.562.1653890597400; Sun, 29 May 2022 23:03:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653890597; cv=none; d=google.com; s=arc-20160816; b=LVwRbbBd9bp6IHGG4g6VJXIIc2nXFXnB34C7FGF7jqtLHs87jzKxuRSUSO0hR5hrtH 7DUqOkAQVn3wBpH+hOq98YlatoKY0d3SawQXw4IWYAyy5p10qx75FdShbhEN1vLicDT5 7/bCDDNI7z5iseUk26ITBMipb0zPcd2yKi/vjYkecGNfvHEaRRU8vZDEK1AfBLgrKhlC lLfqWxqAcBY5341T3xrE5nyh46nXskkWlVrrk/lzm+0GP9LN4n83NOxPPYB2pkgYDrPc XNvnKmk+YWNeBRQFpMx9SLp0tHpy+HsYw9Fe1O6UuTLhYfXIf+dbhtsEesApN+gcVWi0 G5Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=x1qQF7i+tfjIn6BowE49n6fjK1wx+T1Lp6oP/8uwrbU=; b=xHfGSPsasADRsFjUQ01oRmxH4dOyCOunRL+iieabhY85u3TKUyQcJPAy4yIFkYo8jc 0bGvcMBpNif/k7eN74iYMJIrsQs0ofwxZOhNQteKsN+Gi3V0xEv+hGM8Y0tBdQhwB7uW XXWy8HtN6KKjgNDvN4SC3Cv/zrJHAczKBHq3MSdh5WMfGTeEroiWIObsaC3ItOeDgyY0 oPwWjiLIDhBcHr/FXmvaDt4281aa+YfOa+D2M8EioaHyodaRYYr3xk7NTLzW1IOClTY4 99ci8x1oqbfqplXcaAvmWfFo41D9eQAPk6raN/Gsvh010caviOkHnbkAL9oAOGv3wuA3 KfWw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTP id w3-20020a170902d70300b00156542d2adasi419235ply.12.2022.05.29.23.03.17 for ; Sun, 29 May 2022 23:03:17 -0700 (PDT) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id 48C1A20D6E for ; Mon, 30 May 2022 15:03:16 +0900 (JST) Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by gw2.atmark-techno.com (Postfix) with ESMTPS id 34E4220D6E for ; Mon, 30 May 2022 15:03:16 +0900 (JST) Received: by mail-pg1-f198.google.com with SMTP id u8-20020a656708000000b003f70a43fe1eso4144601pgf.3 for ; Sun, 29 May 2022 23:03:16 -0700 (PDT) X-Received: by 2002:a17:902:e845:b0:163:ebca:a025 with SMTP id t5-20020a170902e84500b00163ebcaa025mr1533169plg.81.1653890595277; Sun, 29 May 2022 23:03:15 -0700 (PDT) X-Received: by 2002:a17:902:e845:b0:163:ebca:a025 with SMTP id t5-20020a170902e84500b00163ebcaa025mr1533151plg.81.1653890595033; Sun, 29 May 2022 23:03:15 -0700 (PDT) Received: from pc-0115 (76.125.194.35.bc.googleusercontent.com. [35.194.125.76]) by smtp.gmail.com with ESMTPSA id f3-20020a170902ab8300b00163f2f9f07csm357576plr.48.2022.05.29.23.03.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 May 2022 23:03:11 -0700 (PDT) Received: from martinet by pc-0115 with local (Exim 4.95) (envelope-from ) id 1nvYUf-005RIW-6Y; Mon, 30 May 2022 15:03:09 +0900 From: Dominique Martinet To: swupdate@googlegroups.com, sbabic@denx.de Cc: Dominique Martinet Subject: [swupdate] [PATCH 6/6] core/utils: fix missing NULL return value check Date: Mon, 30 May 2022 15:03:04 +0900 Message-Id: <20220530060304.1296389-7-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220530060304.1296389-1-dominique.martinet@atmark-techno.com> References: <20220530060304.1296389-1-dominique.martinet@atmark-techno.com> MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , in case of allocation failures string_split or strdup could return NULL. This is not actually possible on default linux, but static analysis is always noisy about these... Reported-by: gcc -fanalyzer Signed-off-by: Dominique Martinet --- core/util.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/util.c b/core/util.c index d9df906f090f..3724182f1e4d 100644 --- a/core/util.c +++ b/core/util.c @@ -979,6 +979,10 @@ static char *getroot_abs_path(char* devname) { int fd; char *path; + + if (!devname) + return NULL; + if ((path = realpath(devname, NULL))) { if ((fd = open(path, O_RDWR | O_CLOEXEC)) != -1) { (void)close(fd); @@ -1120,6 +1124,8 @@ static char *get_root_from_cmdline(void) if (ret > 0) { parms = string_split(buf, ' '); + if (!parms) + goto out; int nparms = count_string_array((const char **)parms); for (unsigned int index = 0; index < nparms; index++) { if (!strncmp(parms[index], "root=", strlen("root="))) { @@ -1132,6 +1138,7 @@ static char *get_root_from_cmdline(void) } } } +out: fclose(fp); free_string_array(parms); free(buf); @@ -1181,6 +1188,8 @@ int read_lines_notify(int fd, char *buf, int buf_size, int *buf_offset, } char **lines = string_split(buf, '\n'); + if (!lines) + return -errno; int nlines = count_string_array((const char **)lines); /* * If the buffer is full and there is only one line,