From: Thomas Jarosch Date: Fri, 26 Aug 2011 13:55:20 +0000 (+0200) Subject: Remove MegaAddr hack which gave unix sockets paths up to PATH_MAX: It's incompatible... X-Git-Tag: v0.3~11^2~2 X-Git-Url: http://developer.intra2net.com/git/?p=libasyncio;a=commitdiff_plain;h=a0508232438d4b0ff41644ab5aa7846141b88b42 Remove MegaAddr hack which gave unix sockets paths up to PATH_MAX: It's incompatible with the stack protector --- diff --git a/asyncio/async_socket.cpp b/asyncio/async_socket.cpp index 0e39394..1c4bdc9 100644 --- a/asyncio/async_socket.cpp +++ b/asyncio/async_socket.cpp @@ -43,8 +43,6 @@ namespace AsyncIo namespace { -struct sockaddr_un dummy_un; - /** Struct for holding sockaddr. @@ -54,16 +52,17 @@ struct sockaddr_un dummy_un; This works as long as the POSIX functions don't verify the buffer length. For glibc on linux this is true. + + UPDATE 2011-08-26: + Removed that buffer as the gcc stack protector chokes on this. + + Now we are "limited" to 108 bytes again. The longest socket path + currently in use on the Intranator is 68 bytes. It looks already + longer than Richard Stallman's beard, so it should be fine. */ union MegaAddr { struct sockaddr m_addr; - struct sockaddr_in m_addr_in; struct sockaddr_un m_addr_un; // NOTE (historically) too small... - // storage is large enough to hold all sockaddr_* variants with the (historical) exception of _un ! - struct sockaddr_storage m_addr_store; - // a char array large enough to hold _un (with an path up to the maximum allowed size!) - // (the +1 is added for a later 0-termination of the path) - char m_buffer[ sizeof(dummy_un) - sizeof(dummy_un.sun_path) + PATH_MAX + 1 ]; }; @@ -119,13 +118,7 @@ void ServerSocketBaseImplementation::doRead() return; } - if (addrlen < sizeof(addr)) - { - // in case of unix domain socket: terminate the path! - // NOTE we are doing this here since we don't pass the length info. - addr.m_buffer[addrlen]= 0; - } - else + if (addrlen >= sizeof(addr)) { //something went terribly wrong!! // the resulting address structure is larger than it ever could be... @@ -261,7 +254,10 @@ bool UnixIOSocket::open(const std::string& path) { MegaAddr addr; addr.m_addr_un.sun_family= AF_UNIX; - strncpy(addr.m_addr_un.sun_path, path.c_str(), PATH_MAX); //lint !e419 + + strncpy(addr.m_addr_un.sun_path, path.c_str(), sizeof(addr.m_addr_un.sun_path)); + addr.m_addr_un.sun_path[sizeof(addr.m_addr_un.sun_path)-1] = '\0'; + if (::connect(fd,(sockaddr*)&addr.m_addr_un, SUN_LEN(&addr.m_addr_un)) < 0) //lint !e413 { m_errno= errno; @@ -354,7 +350,10 @@ bool UnixServerSocketBase::open(const std::string& path, int mode) { MegaAddr addr; addr.m_addr_un.sun_family= AF_UNIX; - strncpy(addr.m_addr_un.sun_path, path.c_str(), PATH_MAX); //lint !e419 + + strncpy(addr.m_addr_un.sun_path, path.c_str(), sizeof(addr.m_addr_un.sun_path)); + addr.m_addr_un.sun_path[sizeof(addr.m_addr_un.sun_path)-1] = '\0'; + Utils::unlink(path); // just in case... // NOTE this is a place which might require some updates for multithreaded // usage! (setting the umask affects all threads...)