Recent changes uncovered a NEGATIVE_RETURNS in the return from sysconf()
when processing a for loop in virtTestCaptureProgramExecChild() in
testutils.c
Code review uncovered 3 other code paths with the same condition that
weren't found by Covirity, so fixed those as well.
/* Just in case someone forget to set FD_CLOEXEC, explicitly
* close all FDs before executing the container */
open_max = sysconf(_SC_OPEN_MAX);
+ if (open_max < 0) {
+ virReportSystemError(errno, "%s",
+ _("sysconf(_SC_OPEN_MAX) failed"));
+ goto cleanup;
+ }
for (fd = 0; fd < open_max; fd++)
if (fd != ttyfd && fd != control && fd != handshakefd) {
int tmpfd = fd;
}
openmax = sysconf(_SC_OPEN_MAX);
+ if (openmax < 0) {
+ virReportSystemError(errno, "%s",
+ _("sysconf(_SC_OPEN_MAX) failed"));
+ goto fork_error;
+ }
for (fd = 3; fd < openmax; fd++) {
if (fd == childin || fd == childout || fd == childerr)
continue;
int main(int argc, char **argv) {
size_t i, n;
+ int open_max;
char **origenv;
char **newenv;
char *cwd;
fprintf(log, "ENV:%s\n", newenv[i]);
}
- for (i = 0; i < sysconf(_SC_OPEN_MAX); i++) {
+ open_max = sysconf(_SC_OPEN_MAX);
+ if (open_max < 0)
+ return EXIT_FAILURE;
+ for (i = 0; i < open_max; i++) {
int f;
int closed;
if (i == fileno(log))
goto cleanup;
open_max = sysconf(_SC_OPEN_MAX);
+ if (open_max < 0)
+ goto cleanup;
+
for (i = 0; i < open_max; i++) {
if (i != stdinfd &&
i != pipefd) {