ruby-changes:8365
From: nobu <ko1@a...>
Date: Thu, 23 Oct 2008 11:18:30 +0900 (JST)
Subject: [ruby-changes:8365] Ruby:r19895 (trunk): * ext/socket/socket.c (sock_s_getservbyport): the port should be
nobu 2008-10-23 11:18:00 +0900 (Thu, 23 Oct 2008) New Revision: 19895 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19895 Log: * 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. Modified files: trunk/ChangeLog trunk/ext/socket/socket.c Index: ChangeLog =================================================================== --- ChangeLog (revision 19894) +++ ChangeLog (revision 19895) @@ -1,3 +1,9 @@ +Thu Oct 23 11:17:58 2008 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * ext/socket/socket.c (sock_s_getservbyport): cast to get rid of Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 19894) +++ ext/socket/socket.c (revision 19895) @@ -3249,14 +3249,16 @@ { 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); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/