public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] lib: sha1, md5, use memmove to move bytes inside buffer, not memcpy.
@ 2017-10-16 11:00 Mark Wielaard
  2017-10-16 14:21 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2017-10-16 11:00 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] lib: sha1, md5, use memmove to move bytes inside buffer, not memcpy.
  2017-10-16 11:00 [PATCH] lib: sha1, md5, use memmove to move bytes inside buffer, not memcpy Mark Wielaard
@ 2017-10-16 14:21 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2017-10-16 14:21 UTC (permalink / raw)
  To: elfutils-devel

On Mon, 2017-10-16 at 13:00 +0200, Mark Wielaard wrote:
> 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.

I am retracting this patch since I noticed nothing was actually using
this code except for one testcase. I'll post a patch removing the
implementation and the testcase.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-16 14:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-16 11:00 [PATCH] lib: sha1, md5, use memmove to move bytes inside buffer, not memcpy Mark Wielaard
2017-10-16 14:21 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).