From 81ba64bd417da0de8a4e22352e9d536d76419c98 Mon Sep 17 00:00:00 2001 From: mame Date: Sat, 17 May 2008 17:56:41 +0000 Subject: * pack.c (pack_pack): check errno to detect error of ruby_strtoul. * pack.c (pack_unpack): ditto. * test/ruby/test_pack.rb: add a test for above. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- pack.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'pack.c') diff --git a/pack.c b/pack.c index c5a5337ea..255f74de8 100644 --- a/pack.c +++ b/pack.c @@ -12,6 +12,7 @@ #include "ruby/ruby.h" #include #include +#include #define SIZE16 2 #define SIZE32 4 @@ -491,7 +492,11 @@ pack_pack(VALUE ary, VALUE fmt) p++; } else if (ISDIGIT(*p)) { + errno = 0; len = STRTOUL(p, (char**)&p, 10); + if (errno) { + rb_raise(rb_eRangeError, "pack length too big"); + } } else { len = 1; @@ -1350,7 +1355,11 @@ pack_unpack(VALUE str, VALUE fmt) p++; } else if (ISDIGIT(*p)) { + errno = 0; len = STRTOUL(p, (char**)&p, 10); + if (errno) { + rb_raise(rb_eRangeError, "pack length too big"); + } } else { len = (type != '@'); -- cgit