aboutsummaryrefslogtreecommitdiffstats
path: root/ext/socket
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/socket.c4
1 files changed, 4 insertions, 0 deletions
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);