From: Jérémie Galarneau Date: Fri, 31 Aug 2018 17:33:51 +0000 (-0400) Subject: Fix: runas check fd value before calling close() X-Git-Tag: v2.11.0-rc1~7 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9abb7e4a8758e6894872d81aef285aa2b521318a;p=lttng-tools.git Fix: runas check fd value before calling close() A bug could cause an 'open' command to return no FD in which case the initial value of '-1' would be used in the call to close(). Reported-by: Coverity Scan (1395329 Improper use of negative value) Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/runas.c b/src/common/runas.c index debc95926..f3adf7355 100644 --- a/src/common/runas.c +++ b/src/common/runas.c @@ -466,6 +466,9 @@ int cleanup_received_fd(enum run_as_cmd cmd, int fd) return 0; } + if (fd < 0) { + return 0; + } ret = close(fd); if (ret < 0) { PERROR("close error");