[RFC,v4,5/9] libcamera: process: Ensure that file descriptors are nonnegative
diff mbox series

Message ID 20250424112203.445351-6-barnabas.pocze@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: process: Remove `ProcessManager` singleton
Related show

Commit Message

Barnabás Pőcze April 24, 2025, 11:21 a.m. UTC
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 <barnabas.pocze@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/process.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

Patch
diff mbox series

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<int> &fds)
 	std::vector<int> v(fds);
 	sort(v.begin(), v.end());
 
+	ASSERT(v.empty() || v.front() >= 0);
+
 	DIR *dir = opendir("/proc/self/fd");
 	if (!dir)
 		return;