mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) 61b7f86248
* 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@oriontransfer.co.nz> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d4e1eb1dfd
commit
d5e7ea9e21
2 changed files with 9 additions and 10 deletions
|
|
@ -109,6 +109,7 @@ rsock_send_blocking(void *data)
|
|||
struct recvfrom_arg {
|
||||
int fd, flags;
|
||||
VALUE str;
|
||||
size_t length;
|
||||
socklen_t alen;
|
||||
union_sockaddr buf;
|
||||
};
|
||||
|
|
@ -119,10 +120,11 @@ recvfrom_blocking(void *data)
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +142,6 @@ rsock_strbuf(VALUE str, long buflen)
|
|||
} else {
|
||||
rb_str_modify_expand(str, buflen - len);
|
||||
}
|
||||
rb_str_set_len(str, buflen);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
@ -176,6 +177,7 @@ rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
|
|||
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),
|
||||
|
|
@ -186,9 +188,8 @@ rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
|
|||
}
|
||||
}
|
||||
|
||||
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:
|
||||
|
|
@ -321,6 +322,7 @@ rsock_read_nonblock(VALUE sock, VALUE length, VALUE buf, VALUE ex)
|
|||
GetOpenFile(sock, fptr);
|
||||
|
||||
if (len == 0) {
|
||||
rb_str_set_len(str, 0);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
@ -338,12 +340,9 @@ rsock_read_nonblock(VALUE sock, VALUE length, VALUE buf, VALUE ex)
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#define RUBY_VERSION "2.5.8"
|
||||
#define RUBY_RELEASE_DATE "2020-03-31"
|
||||
#define RUBY_PATCHLEVEL 222
|
||||
#define RUBY_PATCHLEVEL 223
|
||||
|
||||
#define RUBY_RELEASE_YEAR 2020
|
||||
#define RUBY_RELEASE_MONTH 3
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue