Bug Summary

File:jdk/src/java.base/unix/native/libnio/ch/UnixDomainSockets.c
Warning:line 55, column 24
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 UnixDomainSockets.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/UnixDomainSockets.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 <poll.h>
27#include <sys/types.h>
28#include <sys/socket.h>
29#include <string.h>
30#include <stddef.h>
31#include <netinet/in.h>
32#include <netinet/tcp.h>
33#include <limits.h>
34
35#include "jni.h"
36#include "java_props.h"
37#include "jni_util.h"
38#include "jvm.h"
39#include "jlong.h"
40#include "sun_nio_ch_Net.h"
41#include "nio_util.h"
42#include "nio.h"
43
44/* Subtle platform differences in how unnamed sockets (empty path)
45 * are returned from getsockname()
46 */
47#ifdef MACOSX
48 #define ZERO_PATHLEN(len)(len == __builtin_offsetof(struct sockaddr_un, sun_path)) (JNI_FALSE0)
49#else
50 #define ZERO_PATHLEN(len)(len == __builtin_offsetof(struct sockaddr_un, sun_path)) (len == offsetof(struct sockaddr_un, sun_path)__builtin_offsetof(struct sockaddr_un, sun_path))
51#endif
52
53jbyteArray sockaddrToUnixAddressBytes(JNIEnv *env, struct sockaddr_un *sa, socklen_t len)
54{
55 if (sa->sun_family == AF_UNIX1) {
4
The left operand of '==' is a garbage value
56 int namelen;
57 if (ZERO_PATHLEN(len)(len == __builtin_offsetof(struct sockaddr_un, sun_path))) {
58 namelen = 0;
59 } else {
60 namelen = strlen(sa->sun_path);
61 }
62 jbyteArray name = (*env)->NewByteArray(env, namelen);
63 if (namelen != 0) {
64 (*env)->SetByteArrayRegion(env, name, 0, namelen, (jbyte*)sa->sun_path);
65 if ((*env)->ExceptionOccurred(env)) {
66 return NULL((void*)0);
67 }
68 }
69 return name;
70 }
71 return NULL((void*)0);
72}
73
74jint unixSocketAddressToSockaddr(JNIEnv *env, jbyteArray path, struct sockaddr_un *sa, int *len)
75{
76 memset(sa, 0, sizeof(struct sockaddr_un));
77 sa->sun_family = AF_UNIX1;
78 int ret;
79 const char* pname = (const char *)(*env)->GetByteArrayElements(env, path, NULL((void*)0));
80 if (pname == NULL((void*)0)) {
81 JNU_ThrowByName(env, JNU_JAVANETPKG"java/net/" "SocketException", "Unix domain path not present");
82 return -1;
83 }
84 size_t name_len = (*env)->GetArrayLength(env, path);
85 if (name_len > MAX_UNIX_DOMAIN_PATH_LEN(int)(sizeof(((struct sockaddr_un *)0)->sun_path)-2)) {
86 JNU_ThrowByName(env, JNU_JAVANETPKG"java/net/" "SocketException", "Unix domain path too long");
87 ret = -1;
88 } else {
89 memcpy(sa->sun_path, pname, name_len);
90 *len = (int)(offsetof(struct sockaddr_un, sun_path)__builtin_offsetof(struct sockaddr_un, sun_path) + name_len + 1);
91 ret = 0;
92 }
93 (*env)->ReleaseByteArrayElements(env, path, (jbyte *)pname, 0);
94 return ret;
95}
96
97JNIEXPORT__attribute__((visibility("default"))) jboolean JNICALL
98Java_sun_nio_ch_UnixDomainSockets_init(JNIEnv *env, jclass cl)
99{
100 return JNI_TRUE1;
101}
102
103JNIEXPORT__attribute__((visibility("default"))) jint JNICALL
104Java_sun_nio_ch_UnixDomainSockets_socket0(JNIEnv *env, jclass cl)
105{
106 int fd = socket(PF_UNIX1, SOCK_STREAMSOCK_STREAM, 0);
107 if (fd < 0) {
108 return handleSocketError(env, errno(*__errno_location ()));
109 }
110 return fd;
111}
112
113JNIEXPORT__attribute__((visibility("default"))) void JNICALL
114Java_sun_nio_ch_UnixDomainSockets_bind0(JNIEnv *env, jclass clazz, jobject fdo, jbyteArray path)
115{
116 struct sockaddr_un sa;
117 int sa_len = 0;
118 int rv = 0;
119
120 if (unixSocketAddressToSockaddr(env, path, &sa, &sa_len) != 0)
121 return;
122
123 rv = bind(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
124 if (rv != 0) {
125 handleSocketError(env, errno(*__errno_location ()));
126 }
127}
128
129JNIEXPORT__attribute__((visibility("default"))) jint JNICALL
130Java_sun_nio_ch_UnixDomainSockets_connect0(JNIEnv *env, jclass clazz, jobject fdo, jbyteArray path)
131{
132 struct sockaddr_un sa;
133 int sa_len = 0;
134 int rv;
135
136 if (unixSocketAddressToSockaddr(env, path, &sa, &sa_len) != 0) {
137 return IOS_THROWN(-5L);
138 }
139
140 rv = connect(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
141 if (rv != 0) {
142 if (errno(*__errno_location ()) == EINPROGRESS115) {
143 return IOS_UNAVAILABLE(-2L);
144 } else if (errno(*__errno_location ()) == EINTR4) {
145 return IOS_INTERRUPTED(-3L);
146 }
147 return handleSocketError(env, errno(*__errno_location ()));
148 }
149 return 1;
150}
151
152JNIEXPORT__attribute__((visibility("default"))) jint JNICALL
153Java_sun_nio_ch_UnixDomainSockets_accept0(JNIEnv *env, jclass clazz, jobject fdo, jobject newfdo,
154 jobjectArray array)
155{
156 jint fd = fdval(env, fdo);
157 jint newfd;
158 struct sockaddr_un sa;
159 socklen_t sa_len = sizeof(struct sockaddr_un);
160 jbyteArray address;
161
162 newfd = accept(fd, (struct sockaddr *)&sa, &sa_len);
163 if (newfd < 0) {
164 if (errno(*__errno_location ()) == EAGAIN11 || errno(*__errno_location ()) == EWOULDBLOCK11)
165 return IOS_UNAVAILABLE(-2L);
166 if (errno(*__errno_location ()) == EINTR4)
167 return IOS_INTERRUPTED(-3L);
168 JNU_ThrowIOExceptionWithLastError(env, "Accept failed");
169 return IOS_THROWN(-5L);
170 }
171
172 setfdval(env, newfdo, newfd);
173
174 address = sockaddrToUnixAddressBytes(env, &sa, sa_len);
175 CHECK_NULL_RETURN(address, IOS_THROWN)do { if ((address) == ((void*)0)) { return ((-5L)); } } while
(0)
;
176
177 (*env)->SetObjectArrayElement(env, array, 0, address);
178
179 return 1;
180}
181
182JNIEXPORT__attribute__((visibility("default"))) jbyteArray JNICALL
183Java_sun_nio_ch_UnixDomainSockets_localAddress0(JNIEnv *env, jclass clazz, jobject fdo)
184{
185 struct sockaddr_un sa;
186 socklen_t sa_len = sizeof(struct sockaddr_un);
187 int port;
188 if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
1
Assuming the condition is false
2
Taking false branch
189 handleSocketError(env, errno(*__errno_location ()));
190 return NULL((void*)0);
191 }
192 return sockaddrToUnixAddressBytes(env, &sa, sa_len);
3
Calling 'sockaddrToUnixAddressBytes'
193}
194