Skip to content

Commit d499524

Browse files
peterzhu2118eregon
authored andcommitted
Set string length in string_spec_RSTRING_PTR_read
Since we do not set the length between the call to `read(fd, buffer, 30)` and `rb_str_modify_expand(str, 53)`, the length of the string is technically zero. If the call to `rb_str_modify_expand` actually expands the buffer, it will overwrite all the contents from the `read`.
1 parent 011609c commit d499524

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

optional/capi/ext/string_spec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ VALUE string_spec_RSTRING_PTR_read(VALUE self, VALUE str, VALUE path) {
393393
if (read(fd, buffer, 30) < 0) {
394394
rb_syserr_fail(errno, "read");
395395
}
396+
rb_str_set_len(str, 30);
396397

397398
rb_str_modify_expand(str, 53);
398399
rb_ary_push(capacities, SIZET2NUM(rb_str_capacity(str)));

0 commit comments

Comments
 (0)