Bug Summary

File:jdk/src/java.base/unix/native/libnio/ch/InheritedChannel.c
Warning:line 109, column 27
The left operand of '==' is a garbage value

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 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 * Copyright (c) 2003, 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 <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
41static int toInetFamily(SOCKETADDRESS *sa) {
42 return (sa->sa.sa_family == (ipv6_available() ? AF_INET610 : AF_INET2));
43}
44
45JNIEXPORT__attribute__((visibility("default"))) void JNICALL
46Java_sun_nio_ch_InheritedChannel_initIDs(JNIEnv *env, jclass cla)
47{
48 /* Initialize InetAddress IDs before later use of NET_XXX functions */
49 initInetAddressIDs(env);
50}
51
52JNIEXPORT__attribute__((visibility("default"))) jobject JNICALL
53Java_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((void*)0);
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
69JNIEXPORT__attribute__((visibility("default"))) jbyteArray JNICALL
70Java_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((void*)0);
75
76 if (getpeername(fd, (struct sockaddr *)&sa, &len) == 0) {
77 if (sa.sun_family == AF_UNIX1) {
78 remote_sa = sockaddrToUnixAddressBytes(env, &sa, len);
79 }
80 }
81 return remote_sa;
82}
83
84JNIEXPORT__attribute__((visibility("default"))) jint JNICALL
85Java_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
100JNIEXPORT__attribute__((visibility("default"))) jint JNICALL
101Java_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) {
1
Assuming the condition is false
2
Taking false branch
107 return sun_nio_ch_InheritedChannel_AF_UNKNOWN-1L;
108 }
109 if (addr.sa.sa_family == AF_INET2) {
3
The left operand of '==' is a garbage value
110 return sun_nio_ch_InheritedChannel_AF_INET1L;
111 }
112 if (addr.sa.sa_family == AF_INET610) {
113 return sun_nio_ch_InheritedChannel_AF_INET62L;
114 }
115 if (addr.sa.sa_family == AF_UNIX1) {
116 return sun_nio_ch_InheritedChannel_AF_UNIX3L;
117 }
118 return sun_nio_ch_InheritedChannel_AF_UNKNOWN-1L;
119}
120
121JNIEXPORT__attribute__((visibility("default"))) jboolean JNICALL
122Java_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_FALSE0;
129 }
130 return JNI_TRUE1;
131}
132
133JNIEXPORT__attribute__((visibility("default"))) jint JNICALL
134Java_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_SOCKET1, SO_TYPE3, (void *)&sotype, &arglen) == 0) {
139 if (sotype == SOCK_STREAMSOCK_STREAM)
140 return sun_nio_ch_InheritedChannel_SOCK_STREAM1L;
141 if (sotype == SOCK_DGRAMSOCK_DGRAM)
142 return sun_nio_ch_InheritedChannel_SOCK_DGRAM2L;
143 }
144 return sun_nio_ch_InheritedChannel_UNKNOWN-1L;
145}
146
147JNIEXPORT__attribute__((visibility("default"))) jint JNICALL
148Java_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
157JNIEXPORT__attribute__((visibility("default"))) void JNICALL
158Java_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
165JNIEXPORT__attribute__((visibility("default"))) jint JNICALL
166Java_sun_nio_ch_InheritedChannel_open0(JNIEnv *env, jclass cla, jstring path, jint oflag)
167{
168 const char *str;
169 int oflag_actual;
170
171 /* convert to OS specific value */
172 switch (oflag) {
173 case sun_nio_ch_InheritedChannel_O_RDWR2L :
174 oflag_actual = O_RDWR02;
175 break;
176 case sun_nio_ch_InheritedChannel_O_RDONLY0L :
177 oflag_actual = O_RDONLY00;
178 break;
179 case sun_nio_ch_InheritedChannel_O_WRONLY1L :
180 oflag_actual = O_WRONLY01;
181 break;
182 default :
183 JNU_ThrowInternalError(env, "Unrecognized file mode");
184 return -1;
185 }
186
187 str = JNU_GetStringPlatformChars(env, path, NULL((void*)0));
188 if (str == NULL((void*)0)) {
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
200JNIEXPORT__attribute__((visibility("default"))) void JNICALL
201Java_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}