[Lldb-commits] [lldb] Fix connecting via abstract socket (PR #136466)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Apr 23 03:55:55 PDT 2025
================
@@ -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
More information about the lldb-commits
mailing list