From 409293eb09480ad5a1857496e0ad8147e2576057 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 23 Oct 2008 07:16:20 +0000 Subject: * ext/socket/socket.c (sock_s_getservbyport): check if the port range. [ruby-core:19460] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/socket/socket.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ext/socket') 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); -- cgit v1.2.3