From 189febdf243244c963d5a370601eabd4423ac2f7 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 31 Mar 2004 02:59:57 +0000 Subject: [PATCH] * pack.c (pack_pack): raises RangeError if uv is out of UTF8 value range. [ruby-dev:23281] * io.c (rb_io_binmode): stdio buffer should be empty when calling IO#binmode. [ruby-talk:96155] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6054 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ ext/socket/socket.c | 23 ++++++++++++++++------- io.c | 3 +++ pack.c | 6 +++++- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6755bf400f..d95a38a3ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,14 @@ Wed Mar 31 11:52:39 2004 Nobuyoshi Nakada * lib/delegate.rb (DelegateClass): define internal methods of the result class, but not metaclass of the caller. +Wed Mar 31 11:17:16 2004 Yukihiro Matsumoto + + * pack.c (pack_pack): raises RangeError if uv is out of UTF8 value + range. [ruby-dev:23281] + + * io.c (rb_io_binmode): stdio buffer should be empty when calling + IO#binmode. [ruby-talk:96155] + Tue Mar 30 20:25:34 2004 Tanaka Akira * time.c (search_time_t): limit guess range by mktime if it is diff --git a/ext/socket/socket.c b/ext/socket/socket.c index e62837891b..3bbc5fc8ea 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -528,6 +528,15 @@ bsock_do_not_rev_lookup_set(self, val) return val; } +static void +raise_socket_error(reason, error) + char *reason; + int error; +{ + if (error == EAI_SYSTEM) rb_sys_fail(reason); + rb_raise(rb_eSocket, "%s: %s", reason, gai_strerror(error)); +} + static void make_ipaddr0(addr, buf, len) struct sockaddr *addr; @@ -538,7 +547,7 @@ make_ipaddr0(addr, buf, len) error = getnameinfo(addr, SA_LEN(addr), buf, len, NULL, 0, NI_NUMERICHOST); if (error) { - rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error)); + raise_socket_error("getnameinfo", error); } } @@ -680,7 +689,7 @@ sock_addrinfo(host, port, socktype, flags) if (hostp && hostp[strlen(hostp)-1] == '\n') { rb_raise(rb_eSocket, "newline at the end of hostname"); } - rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error)); + raise_socket_error("getaddrinfo", error); } #if defined(__APPLE__) && defined(__MACH__) @@ -744,14 +753,14 @@ ipaddr(sockaddr, norevlookup) error = getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf), NULL, 0, 0); if (error) { - rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error)); + raise_socket_error("getnameinfo", error); } addr1 = rb_str_new2(hbuf); } error = getnameinfo(sockaddr, SA_LEN(sockaddr), hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), NI_NUMERICHOST | NI_NUMERICSERV); if (error) { - rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error)); + raise_socket_error("getnameinfo", error); } addr2 = rb_str_new2(hbuf); if (norevlookup) { @@ -2210,7 +2219,7 @@ sock_s_getaddrinfo(argc, argv) } error = getaddrinfo(hptr, pptr, &hints, &res); if (error) { - rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error)); + raise_socket_error("getaddrinfo", error); } ret = make_addrinfo(res); @@ -2347,11 +2356,11 @@ sock_s_getnameinfo(argc, argv) error_exit_addr: if (res) freeaddrinfo(res); - rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error)); + raise_socket_error("getaddrinfo", error); error_exit_name: if (res) freeaddrinfo(res); - rb_raise(rb_eSocket, "getnameinfo: %s", gai_strerror(error)); + raise_socket_error("getnameinfo", error); } static VALUE diff --git a/io.c b/io.c index 637dfeae3e..ef46499920 100644 --- a/io.c +++ b/io.c @@ -2133,6 +2133,9 @@ rb_io_binmode(io) OpenFile *fptr; GetOpenFile(io, fptr); + if ((fptr->mode & FMODE_BINMODE) && READ_DATA_BUFFERED(fptr->f)) { + rb_raise(rb_eIOError, "buffer already filled with text-mode content"); + } #ifdef __human68k__ if (fptr->f) fmode(fptr->f, _IOBIN); diff --git a/pack.c b/pack.c index 9680b0fd7f..f011a1f2c4 100644 --- a/pack.c +++ b/pack.c @@ -866,8 +866,12 @@ pack_pack(ary, fmt) int le; from = NEXTFROM; + from = rb_to_int(from); l = num2i32(from); le = uv_to_utf8(buf, l); + if (TYPE(from) == T_BIGNUM) { + rb_raise(rb_eRangeError, "pack(U): value out of range"); + } rb_str_buf_cat(res, (char*)buf, le); } break; @@ -2024,7 +2028,7 @@ uv_to_utf8(buf, uv) buf[5] = (uv&0x3f)|0x80; return 6; } - rb_raise(rb_eArgError, "pack(U): value out of range"); + rb_raise(rb_eRangeError, "pack(U): value out of range"); } static const long utf8_limits[] = {