1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

time.c (time_mdump): use another buffer for year_extend

ruby_marshal_write_long may write 9 bytes, but buf has only 8 bytes.
So the buffer cannot be reused.  This issue was found by Coverity Scan.
This commit is contained in:
Yusuke Endoh 2019-07-15 06:42:55 +09:00
parent ea71128573
commit d37da60128

6
time.c
View file

@ -5090,15 +5090,15 @@ time_mdump(VALUE time)
* binary (like as Fixnum and Bignum).
*/
size_t ysize = rb_absint_size(year_extend, NULL);
char *p;
char *p, buf_year_extend[9];
if (ysize > LONG_MAX ||
(i = ruby_marshal_write_long((long)ysize, buf)) < 0) {
(i = ruby_marshal_write_long((long)ysize, buf_year_extend)) < 0) {
rb_raise(rb_eArgError, "year too %s to marshal: %"PRIsVALUE" UTC",
(year == 1900 ? "small" : "big"), vtm.year);
}
rb_str_resize(str, sizeof(buf) + i + ysize);
p = RSTRING_PTR(str) + sizeof(buf);
memcpy(p, buf, i);
memcpy(p, buf_year_extend, i);
p += i;
rb_integer_pack(year_extend, p, ysize, 1, 0, INTEGER_PACK_LITTLE_ENDIAN);
}