[PATCH] lib: sha1, md5, use memmove to move bytes inside buffer, not memcpy.

Mark Wielaard mark@klomp.org
Mon Oct 16 11:00:00 GMT 2017


At the end of {sha1,md5}_process_bytes we move the contents of
ctx->buffer up to the start of the buffer. Since this means the
source and destination overlap we should use memmove, not memcpy.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 lib/ChangeLog | 6 ++++++
 lib/md5.c     | 2 +-
 lib/sha1.c    | 2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/ChangeLog b/lib/ChangeLog
index 6123045..2b91c3a 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,9 @@
+2017-10-16  Mark Wielaard  <mark@klomp.org>
+
+	* md5.c (md5_process_bytes): Use memmove to move bytes inside buffer,
+	not memcpy.
+	* sha1.c (sha1_process_bytes): Likewise.
+
 2017-08-18  Ulf Hermann  <ulf.hermann@qt.io>
 
 	* eu-config.h: Define attribute_packed to either
diff --git a/lib/md5.c b/lib/md5.c
index 40f3044..d6f6302 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -263,7 +263,7 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
 	{
 	  md5_process_block (ctx->buffer, 64, ctx);
 	  left_over -= 64;
-	  memcpy (ctx->buffer, &ctx->buffer[64], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[64], left_over);
 	}
       ctx->buflen = left_over;
     }
diff --git a/lib/sha1.c b/lib/sha1.c
index 6a9b61f..da01610 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -182,7 +182,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
 	{
 	  sha1_process_block (ctx->buffer, 64, ctx);
 	  left_over -= 64;
-	  memcpy (ctx->buffer, &ctx->buffer[64], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[64], left_over);
 	}
       ctx->buflen = left_over;
     }
-- 
1.8.3.1



More information about the Elfutils-devel mailing list