ruby-changes:60607
From: nagachika <ko1@a...>
Date: Tue, 31 Mar 2020 20:21:38 +0900 (JST)
Subject: [ruby-changes:60607] d0012e50ae (ruby_2_6): merge revision: 61b7f86248bd121be2e83768be71ef289e8e5b90
https://git.ruby-lang.org/ruby.git/commit/?id=d0012e50ae From d0012e50aeab3af26705f62aca542c6834922635 Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Tue, 31 Mar 2020 11:21:22 +0000 Subject: merge revision: 61b7f86248bd121be2e83768be71ef289e8e5b90 ext/socket/init.c: do not return uninitialized buffer Resize string buffer only if some data is received in BasicSocket#read_nonblock and some methods. Co-Authored-By: Samuel Williams <samuel.williams@o...> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e diff --git a/ext/socket/init.c b/ext/socket/init.c index 44d1506..259d3b5 100644 --- a/ext/socket/init.c +++ b/ext/socket/init.c @@ -121,6 +121,7 @@ rsock_send_blocking(void *data) https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L121 struct recvfrom_arg { int fd, flags; VALUE str; + size_t length; socklen_t alen; union_sockaddr buf; }; @@ -131,10 +132,11 @@ recvfrom_blocking(void *data) https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L132 struct recvfrom_arg *arg = data; socklen_t len0 = arg->alen; ssize_t ret; - ret = recvfrom(arg->fd, RSTRING_PTR(arg->str), RSTRING_LEN(arg->str), + ret = recvfrom(arg->fd, RSTRING_PTR(arg->str), arg->length, arg->flags, &arg->buf.addr, &arg->alen); if (ret != -1 && len0 < arg->alen) arg->alen = len0; + return (VALUE)ret; } @@ -152,7 +154,6 @@ rsock_strbuf(VALUE str, long buflen) https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L154 } else { rb_str_modify_expand(str, buflen - len); } - rb_str_set_len(str, buflen); return str; } @@ -188,6 +189,7 @@ rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from) https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L189 arg.fd = fptr->fd; arg.alen = (socklen_t)sizeof(arg.buf); arg.str = str; + arg.length = buflen; while (rb_io_check_closed(fptr), rsock_maybe_wait_fd(arg.fd), @@ -198,9 +200,8 @@ rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from) https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L200 } } - if (slen != RSTRING_LEN(str)) { - rb_str_set_len(str, slen); - } + /* Resize the string to the amount of data received */ + rb_str_set_len(str, slen); rb_obj_taint(str); switch (from) { case RECV_RECV: @@ -333,6 +334,7 @@ rsock_read_nonblock(VALUE sock, VALUE length, VALUE buf, VALUE ex) https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L334 GetOpenFile(sock, fptr); if (len == 0) { + rb_str_set_len(str, 0); return str; } @@ -350,12 +352,9 @@ rsock_read_nonblock(VALUE sock, VALUE length, VALUE buf, VALUE ex) https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L352 rb_syserr_fail_path(e, fptr->pathv); } } - if (len != n) { + if (n != RSTRING_LEN(str)) { rb_str_modify(str); rb_str_set_len(str, n); - if (str != buf) { - rb_str_resize(str, n); - } } if (n == 0) { if (ex == Qfalse) return Qnil; diff --git a/version.h b/version.h index ee4c553..27d3f05 100644 --- a/version.h +++ b/version.h @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1 #define RUBY_VERSION "2.6.6" -#define RUBY_RELEASE_DATE "2020-03-30" -#define RUBY_PATCHLEVEL 145 +#define RUBY_RELEASE_DATE "2020-03-31" +#define RUBY_PATCHLEVEL 146 #define RUBY_RELEASE_YEAR 2020 #define RUBY_RELEASE_MONTH 3 -#define RUBY_RELEASE_DAY 30 +#define RUBY_RELEASE_DAY 31 #include "ruby/version.h" -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/