From patchwork Thu Apr 24 11:21:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23247 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 06CBDC3320 for ; Thu, 24 Apr 2025 11:22:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 97BE368B27; Thu, 24 Apr 2025 13:22:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="r48uVZU/"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 537C668AC7 for ; Thu, 24 Apr 2025 13:22:08 +0200 (CEST) Received: from pb-laptop.local (185.221.143.16.nat.pool.zt.hu [185.221.143.16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3F3C91666; Thu, 24 Apr 2025 13:22:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745493726; bh=6SAo2VztWOdl3IaEm7dGNgRt6EEEbGm3QhaZW53aXf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r48uVZU/R5j2T6SsKnmnc9g3tiICHHqYkGHGcl5agl6rP54oZUE8+43zc6+LYTyl8 7LMIQxpS7tdEMA6pMXDqaJUFQ63SBkhx2B0ZlTbP/uC6md8eH7tlS85mLmbl/yTZio /6Sl1afO7d3mt1YRoTlOQfER2MtETx7EiRSAqWWY= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Laurent Pinchart Subject: [RFC PATCH v4 5/9] libcamera: process: Ensure that file descriptors are nonnegative Date: Thu, 24 Apr 2025 13:21:58 +0200 Message-ID: <20250424112203.445351-6-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250424112203.445351-1-barnabas.pocze@ideasonboard.com> References: <20250424112203.445351-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Return `-EINVAL` from `Process::start()` if any of the file descriptors are negative as those most likely signal some kind of issue such as missed error checking. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/process.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp index ca9733d77..1bc7a7f9a 100644 --- a/src/libcamera/process.cpp +++ b/src/libcamera/process.cpp @@ -243,6 +243,11 @@ int Process::start(const std::string &path, if (pid_ > 0) return -EBUSY; + for (int fd : fds) { + if (fd < 0) + return -EINVAL; + } + int childPid = fork(); if (childPid == -1) { ret = -errno; @@ -282,6 +287,8 @@ void Process::closeAllFdsExcept(const std::vector &fds) std::vector v(fds); sort(v.begin(), v.end()); + ASSERT(v.empty() || v.front() >= 0); + DIR *dir = opendir("/proc/self/fd"); if (!dir) return;