libcamera: process: Ensure that file descriptors are nonnegative
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>
This commit is contained in:
@@ -243,6 +243,11 @@ int Process::start(const std::string &path,
|
||||
if (running_)
|
||||
return -EBUSY;
|
||||
|
||||
for (int fd : fds) {
|
||||
if (fd < 0)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int childPid = fork();
|
||||
if (childPid == -1) {
|
||||
ret = -errno;
|
||||
@@ -298,6 +303,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;
|
||||
|
||||
Reference in New Issue
Block a user