summaryrefslogtreecommitdiff
path: root/ext/socket/socket.c
diff options
context:
space:
mode:
authorcharliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-03 10:12:38 +0000
committercharliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-03 10:12:38 +0000
commit8f04556111b25d336838f40aaed34b86a44c9470 (patch)
treef37412d9b762e462c7b4429dd200a1d3845b032d /ext/socket/socket.c
parent12b09864056bfb961f06b0ef675b9fc2fabb9238 (diff)
* ext/socket/socket.c (rsock_sys_fail_host_port): save and restore errno
before calling rb_sys_fail_str to prevent [BUG] errno == 0. Patch by Eric Wong. [ruby-core:59498] [Bug #9352] * ext/socket/socket.c (rsock_sys_fail_path): ditto * ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto * ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto * ext/socket/socket.c (rsock_sys_fail_raddrinfo_or_sockaddr): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r--ext/socket/socket.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 5fd7465..c968598 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -16,12 +16,14 @@ void
rsock_sys_fail_host_port(const char *mesg, VALUE host, VALUE port)
{
VALUE message;
+ int err = errno;
port = rb_String(port);
message = rb_sprintf("%s for \"%s\" port %s",
mesg, StringValueCStr(host), StringValueCStr(port));
+ errno = err;
rb_sys_fail_str(message);
}
@@ -29,6 +31,8 @@ void
rsock_sys_fail_path(const char *mesg, VALUE path)
{
VALUE message;
+ int err = errno;
+
if (RB_TYPE_P(path, T_STRING)) {
if (memchr(RSTRING_PTR(path), '\0', RSTRING_LEN(path))) {
path = rb_str_inspect(path);
@@ -39,6 +43,7 @@ rsock_sys_fail_path(const char *mesg, VALUE path)
message = rb_sprintf("%s for \"%s\"", mesg,
StringValueCStr(path));
}
+ errno = err;
rb_sys_fail_str(message);
}
else {
@@ -50,9 +55,11 @@ void
rsock_sys_fail_sockaddr(const char *mesg, struct sockaddr *addr, socklen_t len)
{
VALUE rai;
+ int err = errno;
rai = rsock_addrinfo_new(addr, len, PF_UNSPEC, 0, 0, Qnil, Qnil);
+ errno = err;
rsock_sys_fail_raddrinfo(mesg, rai);
}
@@ -60,18 +67,24 @@ void
rsock_sys_fail_raddrinfo(const char *mesg, VALUE rai)
{
VALUE str, message;
+ int err = errno;
str = rsock_addrinfo_inspect_sockaddr(rai);
message = rb_sprintf("%s for %s", mesg, StringValueCStr(str));
+ errno = err;
rb_sys_fail_str(message);
}
void
rsock_sys_fail_raddrinfo_or_sockaddr(const char *mesg, VALUE addr, VALUE rai)
{
+ int err = errno;
+
if (NIL_P(rai)) {
StringValue(addr);
+
+ errno = err;
rsock_sys_fail_sockaddr(mesg,
(struct sockaddr *)RSTRING_PTR(addr),
(socklen_t)RSTRING_LEN(addr)); /* overflow should be checked already */