Bug Summary

File:jdk/src/jdk.jdwp.agent/unix/native/libjdwp/exec_md.c
Warning:line 107, column 15
Null pointer passed to 1st parameter expecting 'nonnull'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name exec_md.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjava -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libjava -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -D LIBC=gnu -D _GNU_SOURCE -D _REENTRANT -D _LARGEFILE64_SOURCE -D LINUX -D DEBUG -D _LITTLE_ENDIAN -D ARCH="amd64" -D amd64 -D _LP64=1 -D JDWP_LOGGING -I /home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/unix/native/libjdwp -I /home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/share/native/libjdwp -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/headers/jdk.jdwp.agent -I /home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/share/native/include -I /home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/share/native/libjdwp/export -D _FORTIFY_SOURCE=2 -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wno-unused -Wno-unused-function -std=c99 -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c /home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/unix/native/libjdwp/exec_md.c
1/*
2 * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26#include <stdlib.h>
27#include <unistd.h>
28#include <string.h>
29#include <ctype.h>
30#include "sys.h"
31#include "util.h"
32
33static char *skipWhitespace(char *p) {
34 while ((*p != '\0') && isspace(*p)((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int)
_ISspace)
) {
35 p++;
36 }
37 return p;
38}
39
40static char *skipNonWhitespace(char *p) {
41 while ((*p != '\0') && !isspace(*p)((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int)
_ISspace)
) {
42 p++;
43 }
44 return p;
45}
46
47int
48dbgsysExec(char *cmdLine)
49{
50 int i;
51 int argc;
52 pid_t pid_err = (pid_t)(-1); /* this is the error return value */
53 pid_t pid;
54 char **argv = NULL((void*)0);
55 char *p;
56 char *args;
57
58 /* Skip leading whitespace */
59 cmdLine = skipWhitespace(cmdLine);
60
61 /*LINTED*/
62 args = jvmtiAllocate((jint)strlen(cmdLine)+1);
63 if (args == NULL((void*)0)) {
1
Assuming 'args' is not equal to NULL
2
Taking false branch
64 return SYS_NOMEM-5;
65 }
66 (void)strcpy(args, cmdLine);
67
68 p = args;
69
70 argc = 0;
71 while (*p != '\0') {
3
Assuming the condition is false
4
Loop condition is false. Execution continues on line 81
72 p = skipNonWhitespace(p);
73 argc++;
74 if (*p == '\0') {
75 break;
76 }
77 p = skipWhitespace(p);
78 }
79
80 /*LINTED*/
81 argv = jvmtiAllocate((argc + 1) * (jint)sizeof(char *));
82 if (argv == 0) {
5
Assuming 'argv' is not equal to null
6
Taking false branch
83 jvmtiDeallocate(args);
84 return SYS_NOMEM-5;
85 }
86
87 for (i = 0, p = args; i < argc; i++) {
7
Loop condition is false. Execution continues on line 93
88 argv[i] = p;
89 p = skipNonWhitespace(p);
90 *p++ = '\0';
91 p = skipWhitespace(p);
92 }
93 argv[i] = NULL((void*)0); /* NULL terminate */
8
Storing null pointer value
94
95 if ((pid = fork()) == 0) {
9
Assuming the condition is true
10
Taking true branch
96 /* Child process */
97 int i;
98 long max_fd;
99
100 /* close everything */
101 max_fd = sysconf(_SC_OPEN_MAX_SC_OPEN_MAX);
102 /*LINTED*/
103 for (i = 3; i < (int)max_fd; i++) {
11
Assuming 'i' is >= 'max_fd'
12
Loop condition is false. Execution continues on line 107
104 (void)close(i);
105 }
106
107 (void)execvp(argv[0], argv);
13
Null pointer passed to 1st parameter expecting 'nonnull'
108
109 exit(-1);
110 }
111 jvmtiDeallocate(args);
112 jvmtiDeallocate(argv);
113 if (pid == pid_err) {
114 return SYS_ERR-1;
115 } else {
116 return SYS_OK0;
117 }
118}