Bug Summary

File:jdk/src/jdk.jdwp.agent/share/native/libjdwp/signature.c
Warning:line 50, column 19
Dereference of null pointer (loaded from variable 'tagPtr')

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 signature.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/share/native/libjdwp/signature.c
1/*
2 * Copyright (c) 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 "util.h"
27#include "signature.h"
28
29
30/*
31 * JNI signature constants, beyond those defined in JVM_TYPE(*)
32 */
33#define SIGNATURE_BEGIN_ARGS'(' '('
34#define SIGNATURE_END_ARGS')' ')'
35#define SIGNATURE_END_CLASS';' ';'
36
37char* componentTypeSignature(const char *signature) {
38 jbyte typeKey = jdwpTag(signature);
39 JDI_ASSERT(isArrayTag(typeKey))do { if (gdata && gdata->assertOn && !(isArrayTag
(typeKey))) { jdiAssertionFailed("/home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/share/native/libjdwp/signature.c"
, 39, "isArrayTag(typeKey)"); } } while (0)
;
40 JVM_TYPE_ASSERT(signature[1])do { if (gdata && gdata->assertOn && !(76 ==
signature[1] || 91 == signature[1] || 90 == signature[1] || 66
== signature[1] || 67 == signature[1] || 68 == signature[1] ||
70 == signature[1] || 73 == signature[1] || 74 == signature[
1] || 83 == signature[1] || 86 == signature[1])) { jdiAssertionFailed
("/home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/share/native/libjdwp/signature.c"
, 40, "Tag is not a JVM basic type"); } } while (0)
;
41 return (char*)&signature[1];
42}
43
44jbyte methodSignature_returnTag(char *signature)
45{
46 char *tagPtr = strchr(signature, SIGNATURE_END_ARGS')');
47 JDI_ASSERT(tagPtr)do { if (gdata && gdata->assertOn && !(tagPtr
)) { jdiAssertionFailed("/home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/share/native/libjdwp/signature.c"
, 47, "tagPtr"); } } while (0)
;
1
Assuming 'gdata' is non-null
2
Assuming field 'assertOn' is not equal to 0
3
Assuming 'tagPtr' is null
4
Taking true branch
5
Loop condition is false. Exiting loop
48 tagPtr++; /* 1st character after the end of args */
6
Null pointer value stored to 'tagPtr'
49 JVM_TYPE_ASSERT((jbyte)*tagPtr)do { if (gdata && gdata->assertOn && !(76 ==
(jbyte)*tagPtr || 91 == (jbyte)*tagPtr || 90 == (jbyte)*tagPtr
|| 66 == (jbyte)*tagPtr || 67 == (jbyte)*tagPtr || 68 == (jbyte
)*tagPtr || 70 == (jbyte)*tagPtr || 73 == (jbyte)*tagPtr || 74
== (jbyte)*tagPtr || 83 == (jbyte)*tagPtr || 86 == (jbyte)*tagPtr
)) { jdiAssertionFailed("/home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/share/native/libjdwp/signature.c"
, 49, "Tag is not a JVM basic type"); } } while (0)
;
7
Assuming 'gdata' is null
8
Loop condition is false. Exiting loop
50 return (jbyte)*tagPtr;
9
Dereference of null pointer (loaded from variable 'tagPtr')
51}
52
53void methodSignature_init(char *signature, void **cursor)
54{
55 JDI_ASSERT(signature[0] == SIGNATURE_BEGIN_ARGS)do { if (gdata && gdata->assertOn && !(signature
[0] == '(')) { jdiAssertionFailed("/home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/share/native/libjdwp/signature.c"
, 55, "signature[0] == SIGNATURE_BEGIN_ARGS"); } } while (0)
;
56 *cursor = signature + 1; /* skip to the first arg */
57}
58
59
60jboolean methodSignature_nextArgumentExists(void **cursor, jbyte *argumentTag)
61{
62 char *tagPtr = *cursor;
63 jbyte nextType = (jbyte)*tagPtr;
64
65 if (*tagPtr != SIGNATURE_END_ARGS')') {
66 /* Skip any array modifiers */
67 while (*tagPtr == JDWP_TAG(ARRAY)91) {
68 tagPtr++;
69 }
70 /* Skip class name */
71 if (*tagPtr == JDWP_TAG(OBJECT)76) {
72 tagPtr = strchr(tagPtr, SIGNATURE_END_CLASS';') + 1;
73 JDI_ASSERT(tagPtr)do { if (gdata && gdata->assertOn && !(tagPtr
)) { jdiAssertionFailed("/home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/share/native/libjdwp/signature.c"
, 73, "tagPtr"); } } while (0)
;
74 } else {
75 /* Skip primitive sig */
76 tagPtr++;
77 }
78 }
79 *cursor = tagPtr;
80 if (nextType != SIGNATURE_END_ARGS')') {
81 JVM_TYPE_ASSERT(nextType)do { if (gdata && gdata->assertOn && !(76 ==
nextType || 91 == nextType || 90 == nextType || 66 == nextType
|| 67 == nextType || 68 == nextType || 70 == nextType || 73 ==
nextType || 74 == nextType || 83 == nextType || 86 == nextType
)) { jdiAssertionFailed("/home/daniel/Projects/java/jdk/src/jdk.jdwp.agent/share/native/libjdwp/signature.c"
, 81, "Tag is not a JVM basic type"); } } while (0)
;
82 *argumentTag = nextType;
83 return JNI_TRUE1;
84 }
85 return JNI_FALSE0;
86}
87
88/*
89 * Convert the signature "Ljava/lang/Foo;" to a
90 * classname "java.lang.Foo" compatible with the pattern.
91 * Signature is overwritten in-place.
92 */
93void convertSignatureToClassname(char *convert)
94{
95 char *p;
96
97 p = convert + 1;
98 while ((*p != ';') && (*p != '\0')) {
99 char c = *p;
100 if (c == '/') {
101 *(p-1) = '.';
102 } else if (c == '.') {
103 // class signature of a hidden class is "Ljava/lang/Foo.1234;"
104 // map to "java.lang.Foo/1234"
105 *(p-1) = '/';
106 } else {
107 *(p-1) = c;
108 }
109 p++;
110 }
111 *(p-1) = '\0';
112}