summaryrefslogtreecommitdiffstats
path: root/ext/digest
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-05 17:07:59 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-05 17:07:59 +0000
commit9becc0c1e8472331e773d0b842b05f0357ba1815 (patch)
tree7aac1fc6fdbb8b8e1e789b0df78a384c0f52a731 /ext/digest
parent26f551b95a6c0ca4fd635a54e31c61d5dd9d27a1 (diff)
downloadruby-9becc0c1e8472331e773d0b842b05f0357ba1815.tar.gz
ruby-9becc0c1e8472331e773d0b842b05f0357ba1815.tar.xz
ruby-9becc0c1e8472331e773d0b842b05f0357ba1815.zip
* ext/digest/digest.c (hexdigest_str_new): Add a string size check.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@11088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/digest')
-rw-r--r--ext/digest/digest.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index f56a1921f..63df4b126 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -45,7 +45,14 @@ hexdigest_str_new(const unsigned char *digest, size_t digest_len)
int i;
VALUE str;
char *p;
- static const char hex[] = "0123456789abcdef";
+ static const char hex[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'a', 'b', 'c', 'd', 'e', 'f'
+ };
+
+ if (LONG_MAX / 2 < digest_len) {
+ rb_raise(rb_eRuntimeError, "digest string too long");
+ }
str = rb_str_new(0, digest_len * 2);