aboutsummaryrefslogtreecommitdiffstats
path: root/ext/stringio
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-21 03:15:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-21 03:15:56 +0000
commitda2e7c0c6c63bfb549322c7af2d43154dfc52cfb (patch)
tree7d7e2db416def65f48e23b0997d31efe8d6d42a8 /ext/stringio
parentf247932ff1d891a98f750b084957bca78756d49b (diff)
downloadruby-da2e7c0c6c63bfb549322c7af2d43154dfc52cfb.tar.gz
stringio.c: check character code
* ext/stringio/stringio.c (strio_ungetc): check if the character code is valid in the encoding. reported by Ahmad Sherif (ahmadsherif) at https://hackerone.com/reports/209593. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/stringio')
-rw-r--r--ext/stringio/stringio.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index ba6512366a..d6833976af 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -767,12 +767,14 @@ strio_ungetc(VALUE self, VALUE c)
check_modifiable(ptr);
if (NIL_P(c)) return Qnil;
if (FIXNUM_P(c)) {
- int cc = FIX2INT(c);
+ int len, cc = FIX2INT(c);
char buf[16];
enc = rb_enc_get(ptr->string);
+ len = rb_enc_codelen(cc, enc);
+ if (len <= 0) rb_enc_uint_chr(cc, enc);
rb_enc_mbcput(cc, buf, enc);
- return strio_unget_bytes(ptr, buf, rb_enc_codelen(cc, enc));
+ return strio_unget_bytes(ptr, buf, len);
}
else {
SafeStringValue(c);