From nobody Mon Feb 9 10:50:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1573650454; cv=none; d=zoho.com; s=zohoarc; b=P7qvjlbM3P5e0h4NMqGhsXnUwiIg9osZ3YpF8OoJsJJrctB+qtFyrG40xNSvqY2YcoaW+XnwLu4RdBS79l/+sj2aFb+zOt10hwfDr2hYuYNUyv8BjZ5ZJhB5dpPSbvksWoZ5bAUQz7FpAB+Z+DEZ7sb0ePrmg83mT0gy43BeXQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573650454; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rFwmH1zVwu2iEulIEcL9P/achOWyeqR4vWXurQExirc=; b=Ak6D2dZlgpwyhJzwycPwoS3fZ5gks+ZPoYaNwAUftiQWJ8fRH3Zbt1u5BH1pDmEAGh18ABPKmDZlXhaId8EuDBXy7NsK6xKbbMBN2AdPZZrn74bddc9yMSmsIQt3arTG/8OEsR7C3MEjjX/jmXaSxOhgrMXScUK+c4iskxnAEXo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1573650454658367.86070989322184; Wed, 13 Nov 2019 05:07:34 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-284-047CMdd1MbmqwOQW-vpv8A-1; Wed, 13 Nov 2019 08:07:32 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 577FC107ACC6; Wed, 13 Nov 2019 13:07:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2EF704DA0D; Wed, 13 Nov 2019 13:07:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E13291832DEE; Wed, 13 Nov 2019 13:07:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xADD7JXj007114 for ; Wed, 13 Nov 2019 08:07:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2932160CCC; Wed, 13 Nov 2019 13:07:19 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id A800660BE0 for ; Wed, 13 Nov 2019 13:07:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573650453; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rFwmH1zVwu2iEulIEcL9P/achOWyeqR4vWXurQExirc=; b=GvCVJoy6jIjUPPWin3h2Wl7qMNRKR52zSUp/NWA5XLmWEqKOB4nbW5Y5oFDobKMb1gQEve xAfa4U1+4YwaaLNZFBniG62becZTn1UR1G/zADgUxFtx+Ejx1XMHO/6x62MMq8nB9trjOg DxxSbRPGNqz+TiE2a/Yo+d0hIc5x0p8= From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 13 Nov 2019 14:07:08 +0100 Message-Id: <6746a2314a06ecde4defe0c7793a2f821aab06d0.1573649216.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/8] util: pidfile: Sanitize return values of virPidFileReadPathIfAlive X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 047CMdd1MbmqwOQW-vpv8A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The callers don't actually use the returned errno for reporting errors. Additionally virFileResolveAllLinks returns -1 rather than -errno on error thus you'd get a spurious EPERM even on other errors. Don't try to return errno in this case. Signed-off-by: Peter Krempa --- src/util/virpidfile.c | 50 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index b1b8e54993..4a800b6528 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -182,7 +182,7 @@ int virPidFileRead(const char *dir, * If @binpath is NULL the check for the executable path * is skipped. * - * Returns -errno upon error, or zero on successful + * Returns -1 upon error, or zero on successful * reading of the pidfile. If the PID was not still * alive, zero will be returned, but @pid will be * set to -1. @@ -191,8 +191,8 @@ int virPidFileReadPathIfAlive(const char *path, pid_t *pid, const char *binPath) { - int ret; - bool isLink; + int rc; + bool isLink =3D false; size_t procLinkLen; const char deletedText[] =3D " (deleted)"; size_t deletedTextLen =3D strlen(deletedText); @@ -205,16 +205,15 @@ int virPidFileReadPathIfAlive(const char *path, /* only set this at the very end on success */ *pid =3D -1; - if ((ret =3D virPidFileReadPath(path, &retPid)) < 0) - return ret; + if (virPidFileReadPath(path, &retPid) < 0) + return -1; #ifndef WIN32 /* Check that it's still alive. Safe to skip this sanity check on * mingw, which lacks kill(). */ if (kill(retPid, 0) < 0) { - ret =3D 0; - retPid =3D -1; - goto cleanup; + *pid =3D -1; + return 0; } #endif @@ -222,23 +221,24 @@ int virPidFileReadPathIfAlive(const char *path, /* we only knew the pid, and that pid is alive, so we can * return it. */ - ret =3D 0; - goto cleanup; + *pid =3D retPid; + return 0; } procPath =3D g_strdup_printf("/proc/%lld/exe", (long long)retPid); - if ((ret =3D virFileIsLink(procPath)) < 0) - return ret; + if ((rc =3D virFileIsLink(procPath)) < 0) + return -1; - isLink =3D ret; + if (rc =3D=3D 1) + isLink =3D true; if (isLink && virFileLinkPointsTo(procPath, binPath)) { /* the link in /proc/$pid/exe is a symlink to a file * that has the same inode as the file at binpath. */ - ret =3D 0; - goto cleanup; + *pid =3D retPid; + return 0; } /* Even if virFileLinkPointsTo returns a mismatch, it could be @@ -248,24 +248,22 @@ int virPidFileReadPathIfAlive(const char *path, * part, and see if it has the same canonicalized name as binpath. */ if (!(procLink =3D areadlink(procPath))) - return -errno; + return -1; procLinkLen =3D strlen(procLink); if (procLinkLen > deletedTextLen) procLink[procLinkLen - deletedTextLen] =3D 0; - if ((ret =3D virFileResolveAllLinks(binPath, &resolvedBinPath)) < 0) - return ret; - if ((ret =3D virFileResolveAllLinks(procLink, &resolvedProcLink)) < 0) - return ret; + if (virFileResolveAllLinks(binPath, &resolvedBinPath) < 0) + return -1; + if (virFileResolveAllLinks(procLink, &resolvedProcLink) < 0) + return -1; - ret =3D STREQ(resolvedBinPath, resolvedProcLink) ? 0 : -1; + if (STRNEQ(resolvedBinPath, resolvedProcLink)) + return -1; - cleanup: - /* return the originally set pid of -1 unless we proclaim success */ - if (ret =3D=3D 0) - *pid =3D retPid; - return ret; + *pid =3D retPid; + return 0; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list