================
@@ -182,3 +191,22 @@ std::vector<std::string> 
DomainSocket::GetListeningConnectionURI() const {
 
   return {llvm::formatv("unix-connect://{0}", addr.sun_path)};
 }
+
+Socket *DomainSocket::Create(NativeSocket sockfd, bool should_close,
+                             Status &error) {
+#ifdef __linux__
+  // Check if fd represents domain socket or abstract socket.
+  struct sockaddr_un addr;
+  socklen_t addr_len = sizeof(addr);
+  if (getsockname(sockfd, (struct sockaddr *)&addr, &addr_len) == -1) {
+    error = Status::FromErrorString(
+        "lldb-platform child: not a socket or error occurred");
+    return nullptr;
+  }
+
+  if (addr.sun_family == AF_UNIX && addr.sun_path[0] == '\0') {
----------------
labath wrote:

This also needs to check the value of addr_len as according to 
[this](https://man7.org/linux/man-pages/man7/unix.7.html) the value of sun_path 
is undefined for unnamed sockets.

Also, since we're returning errors, I'd also return one if the provided socket 
is not a unix socket.

So, something like:
```
if (addr.sun_family != AF_UNIX)
  return llvm::createStringError("Bad socket type");
if (addr_len > offsetof(struct sockaddr_un, sun_path) && addr.sun_path[0] == 
'\0')
  return std::make_unique<AbstractSocket>(sockfd, should_close);
```

(note no use of braces for [one-line 
statements](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements))

https://github.com/llvm/llvm-project/pull/136466
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to