Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7338196ybi; Thu, 1 Aug 2019 06:45:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwueBIZFtCMFvJLnrzNmbyqsXBEH5G7fn0QEjqIfUfb0Xx3ox8vxH7tI3RCUqG+RSrx6CHI X-Received: by 2002:a63:7a01:: with SMTP id v1mr121924628pgc.310.1564667143166; Thu, 01 Aug 2019 06:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564667143; cv=none; d=google.com; s=arc-20160816; b=Ow8f37ilAPNdQZlBlHuGPp6D8BX0mH28/BPQgdGB0qmHYpWg2y1+Cn806L+UTuImtp r5lE8og2DtF87qYtVx60rK3HBpvB6IrtVmw/iAmLBxEcyn6LkyRyNgkLe1ADj/cXh8ti MjMShbj6hxpRrWw2yCmno8rjLuzEIJry4+iDBaBWIbeXK3OgII87lyOmuz4jZy+tLoLo yttJttlFuqxXAqR/HOXnCVi2kHTwEzTl1nFs+VYqXwcdkMWFAr3Jz8eN7oxMrbHEoEgT sVIx9B5fX+BLZ1aA2ROrWWg3TKZJqRkZ6XXRALDyTO7HLfNtXPOElxilmwYW7aTbnHmJ uU4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :date:cc:to:from:subject:message-id; bh=k1eox2is9uW887wDw8zOYT3fX4ID9I3WBy53VQIUhcA=; b=rsfqUY7Kv6GEDJ2IGjRW5UQOhd/s0AIsuOQydmSsH2p76FRTmV/9VdJLCqZG+cRpcY CMBBGjrz2YmtFwpPG5XqvjkU+1KiItbYE82vlC44affjwJODuxTbwvNnAsD01BS9AV1B TzZnCluvaO1iEoKriui3t3S0YDqWW6NggJuc5Ps9GhFSMXma5cdYHceQJk6pIYtS363T 704B7eK6sRkIiCah3E1wL4eeDJ8osWIklvfklEo7qc7mo6Zp14riixiIa/kvK9E/4PXY xuB9V1gk/9Bt1/2rjZSkTylkxtP6UJ/+XwCTNIuY/a/y+GCg5m12BLF/poA4rXjWpA4w XEoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v184si36934455pgv.566.2019.08.01.06.45.18; Thu, 01 Aug 2019 06:45:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729985AbfHANcn (ORCPT + 99 others); Thu, 1 Aug 2019 09:32:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42068 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728578AbfHANcn (ORCPT ); Thu, 1 Aug 2019 09:32:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1C28A3B4E for ; Thu, 1 Aug 2019 13:32:43 +0000 (UTC) Received: from jumitche.remote.csb (unknown [10.33.36.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D6A45D6B2; Thu, 1 Aug 2019 13:32:42 +0000 (UTC) Message-ID: <1564666361.8625.10.camel@redhat.com> Subject: [PATCH] nfs-utils: Fix the error handling if the lseek fails From: Alice J Mitchell To: linux-nfs@vger.kernel.org Cc: Steve Dickson Date: Thu, 01 Aug 2019 14:32:41 +0100 Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 01 Aug 2019 13:32:43 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The error case when lseek returns a negative value was not correctly handled, and the error cleanup routine was potentially leaking memory also. Signed-off-by: Alice J Mitchell --- support/nfs/conffile.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index b6400be..6ba8a35 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -500,7 +500,7 @@ conf_readfile(const char *path) if ((stat (path, &sb) == 0) || (errno != ENOENT)) { char *new_conf_addr = NULL; - size_t sz = sb.st_size; + off_t sz; int fd = open (path, O_RDONLY, 0); if (fd == -1) { @@ -517,6 +517,11 @@ conf_readfile(const char *path) /* only after we have the lock, check the file size ready to read it */ sz = lseek(fd, 0, SEEK_END); + if (sz < 0) { + xlog_warn("conf_readfile: unable to determine file size: %s", + strerror(errno)); + goto fail; + } lseek(fd, 0, SEEK_SET); new_conf_addr = malloc(sz+1); @@ -2162,6 +2167,7 @@ conf_write(const char *filename, const char *section, const char *arg, ret = 0; cleanup: + flush_outqueue(&inqueue, NULL); flush_outqueue(&outqueue, NULL); if (buff) -- 1.8.3.1