diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-10-10 07:49:00 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-10-10 07:49:00 +0000 |
commit | c58eb709003d78fcbf21132fa3c5bcaa864cc460 (patch) | |
tree | 61ffc27e1a735ef05e04d6afe1dd52daa15f69ce /ext | |
parent | 072783b5287a3de25971886a4d4c8ee0d2b486d7 (diff) | |
download | ruby-c58eb709003d78fcbf21132fa3c5bcaa864cc460.tar.gz ruby-c58eb709003d78fcbf21132fa3c5bcaa864cc460.tar.xz ruby-c58eb709003d78fcbf21132fa3c5bcaa864cc460.zip |
* ext/digest/digest.c (hexdigest_str_new, bubblebabble_str_new):
Perform StringValue() checks properly.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@11118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/digest/digest.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/ext/digest/digest.c b/ext/digest/digest.c index 8c348078a..53c05f9ef 100644 --- a/ext/digest/digest.c +++ b/ext/digest/digest.c @@ -42,8 +42,8 @@ get_digest_base_metadata(VALUE klass) static VALUE hexdigest_str_new(VALUE str_digest) { - char *digest = RSTRING_PTR(str_digest); - size_t digest_len = RSTRING_LEN(str_digest); + char *digest; + size_t digest_len; int i; VALUE str; char *p; @@ -52,6 +52,10 @@ hexdigest_str_new(VALUE str_digest) 'a', 'b', 'c', 'd', 'e', 'f' }; + StringValue(str_digest); + digest = RSTRING_PTR(str_digest); + digest_len = RSTRING_LEN(str_digest); + if (LONG_MAX / 2 < digest_len) { rb_raise(rb_eRuntimeError, "digest string too long"); } @@ -71,8 +75,8 @@ hexdigest_str_new(VALUE str_digest) static VALUE bubblebabble_str_new(VALUE str_digest) { - char *digest = RSTRING_PTR(str_digest); - size_t digest_len = RSTRING_LEN(str_digest); + char *digest; + size_t digest_len; VALUE str; char *p; int i, j, seed = 1; @@ -84,6 +88,10 @@ bubblebabble_str_new(VALUE str_digest) 'p', 'r', 's', 't', 'v', 'z', 'x' }; + StringValue(str_digest); + digest = RSTRING_PTR(str_digest); + digest_len = RSTRING_LEN(str_digest); + if ((LONG_MAX - 2) / 3 < (digest_len | 1)) { rb_raise(rb_eRuntimeError, "digest string too long"); } |