GCC static analyzer (-fanalyzer) reports the following issue ; we might close file descriptor 3 once in closeDescriptors()
In closeDescriptors() :
int from_fd = STDERR_FILENO + 1; // STDERR_FILENO is 2 => from_fd 3
close(from_fd);
and then again in forkedChildProcess , see the error report :
/jdk/src/jdk.jdwp.agent/unix/native/libjdwp/exec_md.c: In function 'forkedChildProcess':
/jdk/src/jdk.jdwp.agent/unix/native/libjdwp/exec_md.c:137:19: error: double 'close' of file descriptor '3' [CWE-1341] [-Werror=analyzer-fd-double-close]
137 | (void)close(i);
| ^~~~~~~~
'forkedChildProcess': events 1-2
|
| 119 | forkedChildProcess(const char *file, char *const argv[])
| | ^~~~~~~~~~~~~~~~~~
| | |
| | (1) entry to 'forkedChildProcess'
|......
| 123 | if (closeDescriptors() == 0) { /* failed, close the old way */
| | ~~~~~~~~~~~~~~~~~~
| | |
| | (2) calling 'closeDescriptors' from 'forkedChildProcess'
|
+--> 'closeDescriptors': events 3-4
|
| 66 | closeDescriptors(void)
| | ^~~~~~~~~~~~~~~~
| | |
| | (3) entry to 'closeDescriptors'
|......
| 82 | close(from_fd); /* for possible use by opendir() */
| | ~~~~~~~~~~~~~~
| | |
| | (4) first 'close' here
|
<------+
|
'forkedChildProcess': events 5-10
|
| 123 | if (closeDescriptors() == 0) { /* failed, close the old way */
| | ~^~~~~~~~~~~~~~~~~~
| | ||
| | |(5) returning to 'forkedChildProcess' from 'closeDescriptors'
| | (6) following 'true' branch...
|......
| 127 | const rlim_t max_fd = sysconf(_SC_OPEN_MAX);
| | ~~~~~~~~~~~~~~~~~~~~~
| | |
| | (7) ...to here
|......
| 136 | for (; i < max_fd; i++) {
| | ~~~~~~~~~~
| | |
| | (8) following 'true' branch (when 'i < max_fd')...
| 137 | (void)close(i);
| | ~~~~~~~~
| | |
| | (9) ...to here
| | (10) second 'close' here; first 'close' was at (4)
In closeDescriptors() :
int from_fd = STDERR_FILENO + 1; // STDERR_FILENO is 2 => from_fd 3
close(from_fd);
and then again in forkedChildProcess , see the error report :
/jdk/src/jdk.jdwp.agent/unix/native/libjdwp/exec_md.c: In function 'forkedChildProcess':
/jdk/src/jdk.jdwp.agent/unix/native/libjdwp/exec_md.c:137:19: error: double 'close' of file descriptor '3' [CWE-1341] [-Werror=analyzer-fd-double-close]
137 | (void)close(i);
| ^~~~~~~~
'forkedChildProcess': events 1-2
|
| 119 | forkedChildProcess(const char *file, char *const argv[])
| | ^~~~~~~~~~~~~~~~~~
| | |
| | (1) entry to 'forkedChildProcess'
|......
| 123 | if (closeDescriptors() == 0) { /* failed, close the old way */
| | ~~~~~~~~~~~~~~~~~~
| | |
| | (2) calling 'closeDescriptors' from 'forkedChildProcess'
|
+--> 'closeDescriptors': events 3-4
|
| 66 | closeDescriptors(void)
| | ^~~~~~~~~~~~~~~~
| | |
| | (3) entry to 'closeDescriptors'
|......
| 82 | close(from_fd); /* for possible use by opendir() */
| | ~~~~~~~~~~~~~~
| | |
| | (4) first 'close' here
|
<------+
|
'forkedChildProcess': events 5-10
|
| 123 | if (closeDescriptors() == 0) { /* failed, close the old way */
| | ~^~~~~~~~~~~~~~~~~~
| | ||
| | |(5) returning to 'forkedChildProcess' from 'closeDescriptors'
| | (6) following 'true' branch...
|......
| 127 | const rlim_t max_fd = sysconf(_SC_OPEN_MAX);
| | ~~~~~~~~~~~~~~~~~~~~~
| | |
| | (7) ...to here
|......
| 136 | for (; i < max_fd; i++) {
| | ~~~~~~~~~~
| | |
| | (8) following 'true' branch (when 'i < max_fd')...
| 137 | (void)close(i);
| | ~~~~~~~~
| | |
| | (9) ...to here
| | (10) second 'close' here; first 'close' was at (4)
- relates to
-
JDK-8362516 Support of GCC static analyzer (-fanalyzer)
-
- New
-