namespace
{
-struct sockaddr_un dummy_un;
-
/**
Struct for holding sockaddr.
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 ];
};
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...
{
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;
{
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...)