clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name InheritedChannel.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 -I /home/daniel/Projects/java/jdk/src/java.base/linux/native/libnio -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libnio -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libnio -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/headers/java.base -I /home/daniel/Projects/java/jdk/src/java.base/linux/native/libnio/ch -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libnio/ch -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libnio/ch -I /home/daniel/Projects/java/jdk/src/java.base/linux/native/libnio/fs -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libnio/fs -I /home/daniel/Projects/java/jdk/src/java.base/linux/native/libnet -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libnet -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libnet -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-undef -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/java.base/unix/native/libnio/ch/InheritedChannel.c
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | #include <stdlib.h> |
27 | #include <sys/types.h> |
28 | #include <sys/socket.h> |
29 | #include <unistd.h> |
30 | #include <fcntl.h> |
31 | |
32 | #include "jni.h" |
33 | |
34 | #include "jni.h" |
35 | #include "jni_util.h" |
36 | #include "net_util.h" |
37 | #include "nio_util.h" |
38 | |
39 | #include "sun_nio_ch_InheritedChannel.h" |
40 | |
41 | static int toInetFamily(SOCKETADDRESS *sa) { |
42 | return (sa->sa.sa_family == (ipv6_available() ? AF_INET6 : AF_INET)); |
43 | } |
44 | |
45 | JNIEXPORT void JNICALL |
46 | Java_sun_nio_ch_InheritedChannel_initIDs(JNIEnv *env, jclass cla) |
47 | { |
48 | |
49 | initInetAddressIDs(env); |
50 | } |
51 | |
52 | JNIEXPORT jobject JNICALL |
53 | Java_sun_nio_ch_InheritedChannel_inetPeerAddress0(JNIEnv *env, jclass cla, jint fd) |
54 | { |
55 | SOCKETADDRESS sa; |
56 | socklen_t len = sizeof(SOCKETADDRESS); |
57 | jobject remote_ia = NULL; |
58 | jint remote_port; |
59 | |
60 | if (getpeername(fd, &sa.sa, &len) == 0) { |
61 | if (toInetFamily(&sa)) { |
62 | remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port); |
63 | } |
64 | } |
65 | |
66 | return remote_ia; |
67 | } |
68 | |
69 | JNIEXPORT jbyteArray JNICALL |
70 | Java_sun_nio_ch_InheritedChannel_unixPeerAddress0(JNIEnv *env, jclass cla, jint fd) |
71 | { |
72 | struct sockaddr_un sa; |
73 | socklen_t len = sizeof(struct sockaddr_un); |
74 | jobject remote_sa = NULL; |
75 | |
76 | if (getpeername(fd, (struct sockaddr *)&sa, &len) == 0) { |
| 1 | Assuming the condition is true | |
|
| |
77 | if (sa.sun_family == AF_UNIX) { |
| 3 | | The left operand of '==' is a garbage value |
|
78 | remote_sa = sockaddrToUnixAddressBytes(env, &sa, len); |
79 | } |
80 | } |
81 | return remote_sa; |
82 | } |
83 | |
84 | JNIEXPORT jint JNICALL |
85 | Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd) |
86 | { |
87 | SOCKETADDRESS sa; |
88 | socklen_t len = sizeof(SOCKETADDRESS); |
89 | jint remote_port = -1; |
90 | |
91 | if (getpeername(fd, (struct sockaddr *)&sa.sa, &len) == 0) { |
92 | if (toInetFamily(&sa)) { |
93 | NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port); |
94 | } |
95 | } |
96 | |
97 | return remote_port; |
98 | } |
99 | |
100 | JNIEXPORT jint JNICALL |
101 | Java_sun_nio_ch_InheritedChannel_addressFamily(JNIEnv *env, jclass cla, jint fd) |
102 | { |
103 | SOCKETADDRESS addr; |
104 | socklen_t addrlen = sizeof(addr); |
105 | |
106 | if (getsockname(fd, (struct sockaddr *)&addr, &addrlen) < 0) { |
107 | return sun_nio_ch_InheritedChannel_AF_UNKNOWN; |
108 | } |
109 | if (addr.sa.sa_family == AF_INET) { |
110 | return sun_nio_ch_InheritedChannel_AF_INET; |
111 | } |
112 | if (addr.sa.sa_family == AF_INET6) { |
113 | return sun_nio_ch_InheritedChannel_AF_INET6; |
114 | } |
115 | if (addr.sa.sa_family == AF_UNIX) { |
116 | return sun_nio_ch_InheritedChannel_AF_UNIX; |
117 | } |
118 | return sun_nio_ch_InheritedChannel_AF_UNKNOWN; |
119 | } |
120 | |
121 | JNIEXPORT jboolean JNICALL |
122 | Java_sun_nio_ch_InheritedChannel_isConnected(JNIEnv *env, jclass cla, jint fd) |
123 | { |
124 | SOCKETADDRESS addr; |
125 | socklen_t addrlen = sizeof(addr); |
126 | |
127 | if (getpeername(fd, (struct sockaddr *)&addr, &addrlen) < 0) { |
128 | return JNI_FALSE; |
129 | } |
130 | return JNI_TRUE; |
131 | } |
132 | |
133 | JNIEXPORT jint JNICALL |
134 | Java_sun_nio_ch_InheritedChannel_soType0(JNIEnv *env, jclass cla, jint fd) |
135 | { |
136 | int sotype; |
137 | socklen_t arglen = sizeof(sotype); |
138 | if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) == 0) { |
139 | if (sotype == SOCK_STREAM) |
140 | return sun_nio_ch_InheritedChannel_SOCK_STREAM; |
141 | if (sotype == SOCK_DGRAM) |
142 | return sun_nio_ch_InheritedChannel_SOCK_DGRAM; |
143 | } |
144 | return sun_nio_ch_InheritedChannel_UNKNOWN; |
145 | } |
146 | |
147 | JNIEXPORT jint JNICALL |
148 | Java_sun_nio_ch_InheritedChannel_dup(JNIEnv *env, jclass cla, jint fd) |
149 | { |
150 | int newfd = dup(fd); |
151 | if (newfd < 0) { |
152 | JNU_ThrowIOExceptionWithLastError(env, "dup failed"); |
153 | } |
154 | return (jint)newfd; |
155 | } |
156 | |
157 | JNIEXPORT void JNICALL |
158 | Java_sun_nio_ch_InheritedChannel_dup2(JNIEnv *env, jclass cla, jint fd, jint fd2) |
159 | { |
160 | if (dup2(fd, fd2) < 0) { |
161 | JNU_ThrowIOExceptionWithLastError(env, "dup2 failed"); |
162 | } |
163 | } |
164 | |
165 | JNIEXPORT jint JNICALL |
166 | Java_sun_nio_ch_InheritedChannel_open0(JNIEnv *env, jclass cla, jstring path, jint oflag) |
167 | { |
168 | const char *str; |
169 | int oflag_actual; |
170 | |
171 | |
172 | switch (oflag) { |
173 | case sun_nio_ch_InheritedChannel_O_RDWR : |
174 | oflag_actual = O_RDWR; |
175 | break; |
176 | case sun_nio_ch_InheritedChannel_O_RDONLY : |
177 | oflag_actual = O_RDONLY; |
178 | break; |
179 | case sun_nio_ch_InheritedChannel_O_WRONLY : |
180 | oflag_actual = O_WRONLY; |
181 | break; |
182 | default : |
183 | JNU_ThrowInternalError(env, "Unrecognized file mode"); |
184 | return -1; |
185 | } |
186 | |
187 | str = JNU_GetStringPlatformChars(env, path, NULL); |
188 | if (str == NULL) { |
189 | return (jint)-1; |
190 | } else { |
191 | int fd = open(str, oflag_actual); |
192 | if (fd < 0) { |
193 | JNU_ThrowIOExceptionWithLastError(env, str); |
194 | } |
195 | JNU_ReleaseStringPlatformChars(env, path, str); |
196 | return (jint)fd; |
197 | } |
198 | } |
199 | |
200 | JNIEXPORT void JNICALL |
201 | Java_sun_nio_ch_InheritedChannel_close0(JNIEnv *env, jclass cla, jint fd) |
202 | { |
203 | if (close(fd) < 0) { |
204 | JNU_ThrowIOExceptionWithLastError(env, "close failed"); |
205 | } |
206 | } |