summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-25 14:05:10 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-25 14:05:10 +0000
commitc1d27b8c8d29ffc69f12b87e6261ff8fc4fc3701 (patch)
treeb45a988eb3b2188d95ad838149181205fd5e524d /ext
parent16a285491efec73480384c9e498307b94670448b (diff)
* ext/socket/raddrinfo.c (init_unix_addrinfo): refine error message
format. (addrinfo_mload): show more information on "too long AF_UNIX path" error. (addrinfo_unix_path): ditto for "too short AF_UNIX address" and "too long AF_UNIX address" error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35470 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/raddrinfo.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index bd4af345108..f2e0cddc3e3 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -768,8 +768,9 @@ init_unix_addrinfo(rb_addrinfo_t *rai, VALUE path, int socktype)
StringValue(path);
if (sizeof(un.sun_path) <= (size_t)RSTRING_LEN(path))
- rb_raise(rb_eArgError, "too long unix socket path (%ldbytes given but %dbytes max)",
- RSTRING_LEN(path), (int)sizeof(un.sun_path)-1);
+ rb_raise(rb_eArgError,
+ "too long unix socket path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
+ (size_t)RSTRING_LEN(path), sizeof(un.sun_path)-1);
MEMZERO(&un, struct sockaddr_un, 1);
@@ -1304,7 +1305,9 @@ addrinfo_mload(VALUE self, VALUE ary)
StringValue(v);
if (sizeof(uaddr.sun_path) <= (size_t)RSTRING_LEN(v))
- rb_raise(rb_eSocket, "too long AF_UNIX path");
+ rb_raise(rb_eSocket,
+ "too long AF_UNIX path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
+ (size_t)RSTRING_LEN(v), sizeof(uaddr.sun_path)-1);
memcpy(uaddr.sun_path, RSTRING_PTR(v), RSTRING_LEN(v));
len = (socklen_t)sizeof(uaddr);
memcpy(&ss, &uaddr, len);
@@ -1937,9 +1940,12 @@ addrinfo_unix_path(VALUE self)
s = addr->sun_path;
e = (char*)addr + rai->sockaddr_len;
if (e < s)
- rb_raise(rb_eSocket, "too short AF_UNIX address");
+ rb_raise(rb_eSocket, "too short AF_UNIX address: %"PRIuSIZE" bytes given for minimum %"PRIuSIZE" bytes.",
+ (size_t)rai->sockaddr_len, (size_t)(s - (char *)addr));
if (addr->sun_path + sizeof(addr->sun_path) < e)
- rb_raise(rb_eSocket, "too long AF_UNIX address");
+ rb_raise(rb_eSocket,
+ "too long AF_UNIX path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
+ (size_t)(e - addr->sun_path), sizeof(addr->sun_path));
while (s < e && *(e-1) == '\0')
e--;
return rb_str_new(s, e-s);