summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-23 02:18:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-23 02:18:00 +0000
commita5ea0e8c3209343063ff5943b76e8243edaa7914 (patch)
treeb93bb035e043d6f77196376af9f8f5790882c031
parent538d87cf1133a603ea3e671870b0543b5d9f4636 (diff)
* ext/socket/socket.c (sock_s_getservbyport): the port should be
converted before the proto so that the #to_int of the former cannot alter the latter. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/socket/socket.c10
2 files changed, 12 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 25165cc3d2..c5bb86b9a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Thu Oct 23 11:17:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/socket/socket.c (sock_s_getservbyport): the port should be
+ converted before the proto so that the #to_int of the former cannot
+ alter the latter.
+
Thu Oct 23 09:26:22 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/socket/socket.c (sock_s_getservbyport): cast to get rid of
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 06d9f337c0..5788632f8a 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -3249,14 +3249,16 @@ sock_s_getservbyport(int argc, VALUE *argv)
{
VALUE port, proto;
struct servent *sp;
+ long portnum;
+ const char *protoname = "tcp";
rb_scan_args(argc, argv, "11", &port, &proto);
- if (NIL_P(proto)) proto = rb_str_new2("tcp");
- StringValue(proto);
+ portnum = NUM2LONG(port);
+ if (!NIL_P(proto)) protoname = StringValueCStr(proto);
- sp = getservbyport(htons((uint16_t)NUM2INT(port)), StringValueCStr(proto));
+ sp = getservbyport((int)htons((uint16_t)portnum), protoname);
if (!sp) {
- rb_raise(rb_eSocket, "no such service for port %d/%s", NUM2INT(port), RSTRING_PTR(proto));
+ rb_raise(rb_eSocket, "no such service for port %d/%s", (int)portnum, protoname);
}
return rb_tainted_str_new2(sp->s_name);
}