diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-20 01:33:08 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-20 01:33:08 +0000 |
commit | 5755613b87e76fcd22cf333834f2f5c8ace9522e (patch) | |
tree | a69b426df92ca75abb11fc543f55ea72ff01995e /sprintf.c | |
parent | a1f89b8a418d8d8c96388b947bf71772be60da9d (diff) | |
download | ruby-5755613b87e76fcd22cf333834f2f5c8ace9522e.tar.gz |
sprintf.c: string limits
* sprintf.c (ruby__sfvwrite): use long instead of size_t due to
string limits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r-- | sprintf.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -1301,14 +1301,19 @@ ruby__sfvwrite(register rb_printf_buffer *fp, register struct __suio *uio) struct __siov *iov; VALUE result = (VALUE)fp->_bf._base; char *buf = (char*)fp->_p; - size_t len, n; - size_t blen = buf - RSTRING_PTR(result), bsiz = fp->_w; + long len, n; + long blen = buf - RSTRING_PTR(result), bsiz = fp->_w; if (RBASIC(result)->klass) { rb_raise(rb_eRuntimeError, "rb_vsprintf reentered"); } - if ((len = uio->uio_resid) == 0) + if (uio->uio_resid == 0) return 0; +#if SIZE_MAX > LONG_MAX + if (uio->uio_resid >= LONG_MAX) + rb_raise(rb_eRuntimeError, "too big string"); +#endif + len = (long)uio->uio_resid; CHECK(len); buf += blen; fp->_w = bsiz; |