Browse Source

Fix multiple bugs in string comparisons

Michał Kowalczyk 4 years ago
parent
commit
0612bab52b

+ 1 - 2
LibOS/shim/src/fs/chroot/fs.c

@@ -67,8 +67,7 @@ static int chroot_mount (const char * uri, void ** mount_data)
         type = FILE_UNKNOWN;
         uri += 5;
     } else if (strpartcmp_static(uri, "dev:")) {
-        type = strpartcmp_static(uri + static_strlen("dev"), "tty") ?
-               FILE_DEV : FILE_TTY;
+        type = strpartcmp_static(uri + static_strlen("dev:"), "tty") ? FILE_TTY : FILE_DEV;
         uri += 4;
     } else
         return -EINVAL;

+ 3 - 3
Pal/src/host/FreeBSD/db_sockets.c

@@ -766,10 +766,10 @@ static int udp_open (PAL_HANDLE *hdl, const char * type, const char * uri,
     memcpy(buf, uri, len + 1);
     options &= PAL_OPTION_MASK;
 
-    if (!strcmp_static(type, "udp.srv"))
+    if (strcmp_static(type, "udp.srv"))
         return udp_bind(hdl, buf, options);
 
-    if (!strcmp_static(type, "udp"))
+    if (strcmp_static(type, "udp"))
         return udp_connect(hdl, buf, options);
 
     return -PAL_ERROR_NOTSUPPORT;
@@ -908,7 +908,7 @@ static int udp_sendbyaddr (PAL_HANDLE handle, int offset, int len,
     if (handle->sock.fd == PAL_IDX_POISON)
         return -PAL_ERROR_BADHANDLE;
 
-    if (strpartcmp_static(addr, "udp:"))
+    if (!strpartcmp_static(addr, "udp:"))
         return -PAL_ERROR_INVAL;
 
     addr += static_strlen("udp:");

+ 1 - 1
Pal/src/host/Linux-SGX/sgx_main.c

@@ -796,7 +796,7 @@ static int load_enclave (struct pal_enclave * enclave,
         if (strcmp_static(&env[env_i], "IN_GDB=1")) {
             SGX_DBG(DBG_I, "[ Running under GDB ]\n");
             pal_sec->in_gdb = true;
-        } else if (strcmp_static(&env[env_i], "LD_PRELOAD=")) {
+        } else if (strpartcmp_static(&env[env_i], "LD_PRELOAD=")) {
             uint64_t env_i_size = strnlen(&env[env_i], env_size - env_i) + 1;
             memmove(&env[env_i], &env[env_i + env_i_size], env_size - env_i - env_i_size);
             env_size -= env_i_size;

+ 2 - 2
Pal/src/host/Skeleton/db_sockets.c

@@ -62,10 +62,10 @@ static int tcp_open (PAL_HANDLE *handle, const char * type, const char * uri,
     char uri_buf[PAL_SOCKADDR_SIZE];
     memcpy(uri_buf, uri, uri_len);
 
-    if (!strcmp_static(type, "tcp.srv"))
+    if (strcmp_static(type, "tcp.srv"))
         return tcp_listen(handle, uri_buf, create);
 
-    if (!strcmp_static(type, "tcp"))
+    if (strcmp_static(type, "tcp"))
         return tcp_connect(handle, uri_buf, create);
 
     return -PAL_ERROR_NOTSUPPORT;