diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/socket/socket.c | 4 |
2 files changed, 9 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Thu Oct 23 16:16:17 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * ext/socket/socket.c (sock_s_getservbyport): check if the port range. + [ruby-core:19460] + Thu Oct 23 14:08:07 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> * ext/socket/socket.c (sock_s_getservbyname): unuse unnecessary diff --git a/ext/socket/socket.c b/ext/socket/socket.c index a47c6d47df..09abc88c18 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -3254,6 +3254,10 @@ sock_s_getservbyport(int argc, VALUE *argv) rb_scan_args(argc, argv, "11", &port, &proto); portnum = NUM2LONG(port); + if (portnum != (uint16_t)portnum) { + const char *s = portnum > 0 ? "big" : "small"; + rb_raise(rb_eRangeError, "integer %ld too %s to convert into `int16_t'", portnum, s); + } if (!NIL_P(proto)) protoname = StringValueCStr(proto); sp = getservbyport((int)htons((uint16_t)portnum), protoname); |