From patchwork Sun Jun 28 15:13:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1318602 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::53a; helo=mail-ed1-x53a.google.com; envelope-from=swupdate+bncbcxploxj6ikrbkph4l3qkgqe54yiqka@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=kQsCi9WJ; dkim-atps=neutral Received: from mail-ed1-x53a.google.com (mail-ed1-x53a.google.com [IPv6:2a00:1450:4864:20::53a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49vvK82Ypmz9sPF for ; Mon, 29 Jun 2020 01:13:48 +1000 (AEST) Received: by mail-ed1-x53a.google.com with SMTP id a21sf12704193edy.1 for ; Sun, 28 Jun 2020 08:13:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1593357225; cv=pass; d=google.com; s=arc-20160816; b=pa069tUf+sa7q35OfZ+l130XfHbcEXOFyKCF6k3JKKH6AgIkWp8hq13OixzOONnF5h zFKXo3wkBBPT8BFgHqttuX/2MaFhclxeDSxyzfhRsg4gqNyX1r4zh7Er4sZ7ld6FdyN6 bCGfnqRmiYY66kKrEnDBePXzDBC5Jb3ipdW8lsJfNTcXLtbfRyR29D1VknPpGCoMTSKC Zx4wmTVulqVF6hWHLWQEVFYnlzzzKRMA4Dj417zXAbYndUB2NBXM5DoEWEzgxMoTU1CN Vfp2HY7jCxU2D5lGlRb6WAe0YUlmd7WywD3ChaeDHnySnSwVb0LVZamQeelYFp+v8qCY z/QA== 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=UoD4LlY0u7/1rH0F7bSAuhp+Nbp4vB8EbMtLffDO62s=; b=DxkZkmVobhWWYlIcHtkflboipEuus2FcbaivjZ1SkLVIAFczoVsyd6x22OrTPFOsf7 8Wpvri4T7W0ePAYhe2RmxpfJXuq6ZiBkCm1TkoSev0y2vES85iWqC47kiFTx3PROXsaO DhUojDgRADHpep/DlfAeQ8Nxzeud8z5+Xvz5VNpFBDGohotNT+WXUZIJvGO8RXxdlDPu n+Y5rbbTpIG1YOkPV3GLwWYg/k46SaS8QcVHbkoOejxJXg36dl1tcWFANnAAIs7DvzUq OGOCXQZ6vUuWaKMOCPR2cDw/yd8KdH7gZP55zd2ameLfHeSI2TXASxw8ioHP1+9SmYdU GqTA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; 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=UoD4LlY0u7/1rH0F7bSAuhp+Nbp4vB8EbMtLffDO62s=; b=kQsCi9WJqZRELXBCTEVwYVxNwFaOwE/fCJ3uEvTVVdtK1voL2mPcRoHuYyDf3QGIJm f9UJkqoky9gea12cZLyjjMqKz+3iNnC/V+GJ1oIJZAOFTsz/oaI1mCHW5LKtc8rojH5u /DsT60mkI888Xbp/0vhNGg4gh5kpoF2MYgy52SQnFwUcySaI20+A3B5PRDkLISXXnbSn g1ewLsKRpKffP6bwb1arezbAZvtx9tevnZh1Ksff2SHL1vDh4A6jh1WURc2p4RpUBeb8 MeuLf37P9TbWpE3CyZNnyE7qP+tPlIxF4mfsPOvV3z8I1qrTrut1X2Ejh9Z0WiTkFLfH D3Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=UoD4LlY0u7/1rH0F7bSAuhp+Nbp4vB8EbMtLffDO62s=; b=QYaU19/QfBg+9OJ04ONkbjbxAAurfAFIJJXg8OhD1tfQpd+FnF8JjSKouzD0CZm6ev MMxSsIg8pgwy6yowtiDjQQTt4pwaQPKrd9zmX6LUwgiRYbvc9f1zxH5NTW8IQp+xSnvF Ao7pxhfzunR7qE0lowlEQc84F3eRZXf7DZZgBGLMx4Z/Mzo0prPKwBk6ramwxXR5fGSn pledk8bNO9Zl6CqtpOAJSPfSm+bWRAaknbZlEtrS7VTrAX1DuwBXktPK8XRabwQTiaqz BUwWRVY6gzHmvUvd+UyhZnpqwZlEED9gG3TDqgp++wdRJN/oO+oREu0l+QfCVHtzB2m5 JkRA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM53002uf2PnWujgnf8KzNtoyJa803Rqw8m3FXfeF/ynPNCx45XNwm +3UYQBX3D8r+6JVWOZFMKPQ= X-Google-Smtp-Source: ABdhPJzjBsslvYZAJkfdFn1Yy06G+YSkqx9TZtwPjlhQdO6Ua9hTKXiDIUy3XAedsO/hZrOl+vBE5g== X-Received: by 2002:a17:906:2b52:: with SMTP id b18mr10685610ejg.158.1593357225406; Sun, 28 Jun 2020 08:13:45 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:906:9147:: with SMTP id y7ls3728449ejw.6.gmail; Sun, 28 Jun 2020 08:13:44 -0700 (PDT) X-Received: by 2002:a17:906:2318:: with SMTP id l24mr11085895eja.291.1593357224792; Sun, 28 Jun 2020 08:13:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593357224; cv=none; d=google.com; s=arc-20160816; b=DcixERUtEXAs31z1kj9CSBXD0U776Da6GljcjVZEkIakf2IF/Js9+kdOg0wCxOmcTH +gs788ERPIpIxLlm6jYQOK8fuA2YQpkoCk/15Jot820lMr4lGHwlYUgt+VNzEeyBYTrL CT44rryx6Bf65wJjQ/4PhVqGHO+QTmVCHr0VoMnX7J5UE93/3LzPxAeVhCAfKHv65qGr 5ZD09RpPRo056JXdJ9lkWIXqKr7KvPPyoekr9OMq/QLoOg4dXAX+FxDVGZ8WsIDjAggG fTrJSAM7wubiyi3Yo4VAa0NOsnJf710m52ZvY74FEb5VZU3t4vpL7mHBiGwWJQbBrXjK RmbQ== 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=hSbRnxGo5PpfWAghwvfq1+FhC1phDB0puYB2fUadPqE=; b=cfQUnLdTn/McYmvSH2B6cdsuzhHaxur2OG6s06ru4FsoK/bjQ2Je+KQ+DhPGWaXrsT 8eWQaSXRWCYsS1pVJ5UPgcTPrMqrgASnSWlns2+oNAuBzMKzQr214wUa2HQzythz72o5 Vk4+kB7PJjbeS4Ufi72mb0sCkh9+nWbhGy/Ch6gncgpVLmV4+FepYCRkxOmDgCtLt91+ aG9nK9LG4y6o4jjgCTo/RbwvlJhY1K9JYTxdCHjsEso1PUFP6e+7HdC7kzleqTdzk1RQ aeWAZ8WI2LOrmvR1TN71cOfSiNTZn8bZjHAY/KsMZKRlckm+k64KPrqvxY08jNBJOeyZ thIQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id x14si1148154edq.2.2020.06.28.08.13.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jun 2020 08:13:44 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 49vvK44Y7zz1qrfr; Sun, 28 Jun 2020 17:13:44 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 49vvK44Pffz1qw6c; Sun, 28 Jun 2020 17:13:44 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 4M6p6zATqLpG; Sun, 28 Jun 2020 17:13:43 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Sun, 28 Jun 2020 17:13:43 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 8ECB94540601; Sun, 28 Jun 2020 17:13:43 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8uEgF43sy3uO; Sun, 28 Jun 2020 17:13:40 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.64]) by babic.homelinux.org (Postfix) with ESMTP id 48C30454068B; Sun, 28 Jun 2020 17:13:38 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [libubootenv 4/6] Fix coverity #293504 and #293506 Date: Sun, 28 Jun 2020 17:13:34 +0200 Message-Id: <20200628151336.952051-4-sbabic@denx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200628151336.952051-1-sbabic@denx.de> References: <20200628151336.952051-1-sbabic@denx.de> MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de 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: , Return value from lseek was not checked. Signed-off-by: Stefano Babic --- src/uboot_env.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/uboot_env.c b/src/uboot_env.c index 8086463..7707985 100644 --- a/src/uboot_env.c +++ b/src/uboot_env.c @@ -398,12 +398,13 @@ static int is_nand_badblock(struct uboot_flash_env *dev, loff_t start) static int fileread(struct uboot_flash_env *dev, void *data) { - int ret; + int ret = 0; if (dev->offset) - lseek(dev->fd, dev->offset, SEEK_SET); + ret = lseek(dev->fd, dev->offset, SEEK_SET); - ret = read(dev->fd, data, dev->envsize); + if (!ret) + ret = read(dev->fd, data, dev->envsize); return ret; } @@ -420,18 +421,23 @@ static int mtdread(struct uboot_flash_env *dev, void *data) case MTD_ABSENT: case MTD_NORFLASH: if (dev->offset) - lseek(dev->fd, dev->offset, SEEK_SET); + if (lseek(dev->fd, dev->offset, SEEK_SET) < 0) { + ret = -EIO; + break; + } ret = read(dev->fd, data, dev->envsize); break; case MTD_NANDFLASH: if (dev->offset) - lseek(dev->fd, dev->offset, SEEK_SET); + if (lseek(dev->fd, dev->offset, SEEK_SET) < 0) { + ret = -EIO; + break; + } count = dev->envsize; start = dev->offset; blocksize = dev->envsize; sectors = dev->envsectors ? dev->envsectors : 1; - ret = 0; while (count > 0) { skip = is_nand_badblock(dev, start); @@ -587,16 +593,17 @@ fileprotect_out: static int filewrite(struct uboot_flash_env *dev, void *data) { - int ret; + int ret = 0; ret = fileprotect(dev, false); if (ret < 0) return ret; if (dev->offset) - lseek(dev->fd, dev->offset, SEEK_SET); + ret = lseek(dev->fd, dev->offset, SEEK_SET); - ret = write(dev->fd, data, dev->envsize); + if (!ret) + ret = write(dev->fd, data, dev->envsize); fileprotect(dev, true); // no error handling, keep ret from write