From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id D41215A0271; Mon, 10 Oct 2022 10:35:48 +0200 (CEST) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH v3 7/7] util: Check return value of lseek() while reading bound ports from procfs Date: Mon, 10 Oct 2022 10:35:48 +0200 Message-Id: <20221010083548.831309-8-sbrivio@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221010083548.831309-1-sbrivio@redhat.com> References: <20221010083548.831309-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: OBBHPTUS2CHT6546J4GPV3C64OKZGKYE X-Message-ID-Hash: OBBHPTUS2CHT6546J4GPV3C64OKZGKYE X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: <> Archived-At: List-Archive: <> List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Coverity now noticed we're checking most lseek() return values, but not this. Not really relevant, but it doesn't hurt to check we can actually seek before reading lines. Signed-off-by: Stefano Brivio Reviewed-by: David Gibson --- util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/util.c b/util.c index b366167..5b1e08a 100644 --- a/util.c +++ b/util.c @@ -311,10 +311,14 @@ void procfs_scan_listen(struct ctx *c, uint8_t proto, int ip_version, int ns, path = "/proc/net/udp6"; } - if (*fd != -1) - lseek(*fd, 0, SEEK_SET); - else if ((*fd = open(path, O_RDONLY | O_CLOEXEC)) < 0) + if (*fd != -1) { + if (lseek(*fd, 0, SEEK_SET)) { + warn("lseek() failed on %s: %s", path, strerror(errno)); + return; + } + } else if ((*fd = open(path, O_RDONLY | O_CLOEXEC)) < 0) { return; + } lineread_init(&lr, *fd); lineread_get(&lr, &line); /* throw away header */ -- 2.35.1