From: Chris Hanson Date: Sat, 26 Dec 2009 21:33:18 +0000 (-0800) Subject: Fix MD5-UPDATE and MHASH to check their index args correctly. X-Git-Tag: 20100708-Gtk~178^2~1 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=08a157107ed76996ecb5aafa60f3dc033279b77c;p=mit-scheme.git Fix MD5-UPDATE and MHASH to check their index args correctly. --- diff --git a/src/microcode/prmd5.c b/src/microcode/prmd5.c index 10d8943af..48cca989a 100644 --- a/src/microcode/prmd5.c +++ b/src/microcode/prmd5.c @@ -112,9 +112,9 @@ Update CONTEXT with the contents of the substring (STRING,START,END).") CHECK_ARG (2, STRING_P); { SCHEME_OBJECT string = (ARG_REF (2)); - unsigned long l = (STRING_LENGTH (string)); - unsigned long start = (arg_ulong_index_integer (3, l)); - unsigned long end = (arg_integer_in_range (4, start, (l + 1))); + unsigned long end + = (arg_ulong_index_integer (4, ((STRING_LENGTH (string)) + 1))); + unsigned long start = (arg_ulong_index_integer (3, (end + 1))); MD5_UPDATE ((md5_context_arg (1)), (STRING_LOC (string, start)), (end - start)); diff --git a/src/microcode/prmhash.c b/src/microcode/prmhash.c index e51c2b223..2ca98ee6d 100644 --- a/src/microcode/prmhash.c +++ b/src/microcode/prmhash.c @@ -209,9 +209,8 @@ DEFINE_PRIMITIVE ("MHASH", Prim_mhash, 4, 4, 0) CHECK_ARG (2, STRING_P); { SCHEME_OBJECT string = (ARG_REF (2)); - unsigned long l = (STRING_LENGTH (string)); - unsigned long start = (arg_ulong_index_integer (3, l)); - unsigned long end = (arg_integer_in_range (4, start, (l + 1))); + unsigned long end = (arg_ulong_index_integer (4, ((STRING_LENGTH (string)) + 1))); + unsigned long start = (arg_ulong_index_integer (3, (end + 1))); mhash ((arg_context (1)), (STRING_LOC (string, start)), (end - start)); } PRIMITIVE_RETURN (UNSPECIFIC); diff --git a/src/runtime/crypto.scm b/src/runtime/crypto.scm index 1de7d7f42..217d113d5 100644 --- a/src/runtime/crypto.scm +++ b/src/runtime/crypto.scm @@ -261,8 +261,7 @@ USA. (define (mhash-substring hash-type string start end) (let ((context (mhash-init hash-type))) - (if (fix:> end start) - (mhash-update context string start end)) + (mhash-update context string start end) (mhash-end context))) (define (mhash-sum->number sum) @@ -335,8 +334,7 @@ USA. (define (%md5-substring string start end) (let ((context ((ucode-primitive md5-init 0)))) - (if (fix:> end start) - ((ucode-primitive md5-update 4) context string start end)) + ((ucode-primitive md5-update 4) context string start end) ((ucode-primitive md5-final 1) context))) (define md5-sum->number mhash-sum->number)