[RFC PATCH v5 5/9] libcamera: process: Ensure that file descriptors are nonnegative
Barnabás Pőcze
barnabas.pocze at ideasonboard.com
Thu Apr 24 13:40:59 CEST 2025
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 at ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
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<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;
--
2.49.0
More information about the libcamera-devel
mailing list