]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
fix ldns_sha1 overwrites input buffer.
authorMatthijs Mekking <github@pletterpet.nl>
Mon, 2 Dec 2013 11:46:49 +0000 (12:46 +0100)
committerMatthijs Mekking <github@pletterpet.nl>
Mon, 2 Dec 2013 11:46:49 +0000 (12:46 +0100)
sha1.c

diff --git a/sha1.c b/sha1.c
index 5dec680a1b795211570bada532e92024f5f89428..bb2b97b44477fd54c0474d096aa5d837f2cf6530 100644 (file)
--- a/sha1.c
+++ b/sha1.c
@@ -122,19 +122,21 @@ ldns_sha1_update(ldns_sha1_ctx *context, const unsigned char *data, unsigned int
 {
     unsigned int i;
     unsigned int j;
+    unsigned char d[len];
 
+    (void)memcpy((void*)d, data, len);
     j = (unsigned)(uint32_t)((context->count >> 3) & 63);
     context->count += (len << 3);
     if ((j + len) > 63) {
-        memmove(&context->buffer[j], data, (i = 64 - j));
+        memmove(&context->buffer[j], d, (i = 64 - j));
         ldns_sha1_transform(context->state, context->buffer);
         for ( ; i + 63 < len; i += 64) {
-            ldns_sha1_transform(context->state, &data[i]);
+            ldns_sha1_transform(context->state, &d[i]);
         }
         j = 0;
     }
     else i = 0;
-    memmove(&context->buffer[j], &data[i], len - i);
+    memmove(&context->buffer[j], &d[i], len - i);
 }