Bug 1971 – Any SocketException causes program to segfault
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2008-04-04T14:59:00Z
Last change time
2015-06-09T01:14:38Z
Assigned to
nobody
Creator
d
Comments
Comment #0 by d — 2008-04-04T14:59:25Z
strerror_r is incorrectly defined in std.c.string to return a (const char *), but in fact it returns an int (probably an error from when strerror was switched out for the threadsafe strerror_r). In linux/GDC builds SocketException calls strlen() with the return value of strerror_r, causing a segfault.
Comment #1 by d — 2008-04-25T13:07:03Z
Looks like I oversimplified the problem -- see man page for strerror_r at http://linux.die.net/man/3/strerror_r
There are two incompatible versions of strerror_r, the POSIX standard one returns an int and always stores the error string in the supplied buffer. The GNU specific version behaves as Phobos currently assumes, returning a char * and maybe-or-not using the supplied buffer.
The POSIX standard behavior is available in GNU through a #define macro. Note that other platforms such as OS X only support the POSIX version, so I'd argue that for portability the POSIX version should be used in Phobos, or the differences should be abstracted in the D code.