public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] lib: sha1, md5, use memmove to move bytes inside buffer, not memcpy.
Date: Mon, 16 Oct 2017 11:00:00 -0000	[thread overview]
Message-ID: <1508151613-29280-1-git-send-email-mark@klomp.org> (raw)

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

             reply	other threads:[~2017-10-16 11:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-16 11:00 Mark Wielaard [this message]
2017-10-16 14:21 ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1508151613-29280-1-git-send-email-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).