[clang-tools-extra] [libcxx] [clang] [lldb] [compiler-rt] [lld] [llvm] [libunwind] [libc] [flang] [libc++][test] try to directly create socket file in /tmp when filepath is too long (PR #77058)

Mark de Wever via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 08:36:20 PST 2024


================
@@ -320,16 +320,26 @@ struct scoped_test_env
   // allow tests to call this unguarded.
 #if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(_WIN32)
     std::string create_socket(std::string file) {
-        file = sanitize_path(std::move(file));
-
-        ::sockaddr_un address;
-        address.sun_family = AF_UNIX;
-        assert(file.size() <= sizeof(address.sun_path));
-        ::strncpy(address.sun_path, file.c_str(), sizeof(address.sun_path));
-        int fd = ::socket(AF_UNIX, SOCK_STREAM, 0);
-        ::bind(fd, reinterpret_cast<::sockaddr*>(&address), sizeof(address));
-        return file;
+      file = sanitize_path(std::move(file));
+
+      ::sockaddr_un address;
+      address.sun_family = AF_UNIX;
+
+// If file.size() is too big, try to create a file directly inside
+// /tmp to make sure file path is short enough.
+// Android platform warns about tmpnam, since the problem does not appear
+// on Android, let's not apply it for Android.
----------------
mordante wrote:

Not too happy about this, but since we assert afterwards it will fail the test. If that happens we can investigate.

https://github.com/llvm/llvm-project/pull/77058


More information about the cfe-commits mailing list