[PATCH] Fix potential overlap dest buffer

Subsystems: the rest

STALE1772d

5 messages, 4 authors, 2021-10-08 · open the first message on its own page

[PATCH] Fix potential overlap dest buffer

From: Nigel Croxon <hidden>
Date: 2021-08-17 13:14:54

To meet requirements of Common Criteria certification vulnerablility
assessment. Static code analysis has been run and found the following
error.  Overlapping_buffer: The source buffer potentially overlaps
with the destination buffer, which results in undefined
behavior for "memcpy".

The change is to use memmove instead of memcpy.

Signed-off-by: Nigel Croxon <redacted>
---
 sha1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sha1.c b/sha1.c
index 11be7045..89b32f46 100644
--- a/sha1.c
+++ b/sha1.c
@@ -258,7 +258,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[16], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[16], left_over);
 	}
       ctx->buflen = left_over;
     }
-- 
2.29.2

Re: [PATCH] Fix potential overlap dest buffer

From: NeilBrown <hidden>
Date: 2021-08-17 21:40:14

On Tue, 17 Aug 2021, Nigel Croxon wrote:
To meet requirements of Common Criteria certification vulnerablility
assessment. Static code analysis has been run and found the following
error.  Overlapping_buffer: The source buffer potentially overlaps
with the destination buffer, which results in undefined
behavior for "memcpy".

The change is to use memmove instead of memcpy.

Signed-off-by: Nigel Croxon <redacted>
Reviewed-by: NeilBrown <redacted>

Thanks,
NeilBrown

quoted hunk
---
 sha1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sha1.c b/sha1.c
index 11be7045..89b32f46 100644
--- a/sha1.c
+++ b/sha1.c
@@ -258,7 +258,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[16], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[16], left_over);
 	}
       ctx->buflen = left_over;
     }
-- 
2.29.2

Re: [PATCH] Fix potential overlap dest buffer

From: Paul Menzel <hidden>
Date: 2021-08-18 06:34:40

Dear Nigel,


Am 17.08.21 um 15:14 schrieb Nigel Croxon:
To meet requirements of Common Criteria certification vulnerablility
vulnerability
assessment.
That’s only part of a sentence? Is that supposed to be read as a 
continuation of the commit message summary: … to meet requirements …?
Static code analysis has been run and found the following
error.  Overlapping_buffer: The source buffer potentially overlaps
It’d be great, if you denoted, which tool was run. Maybe even add a 
Found-by tag.
quoted hunk
with the destination buffer, which results in undefined
behavior for "memcpy".

The change is to use memmove instead of memcpy.

Signed-off-by: Nigel Croxon <redacted>
---
  sha1.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sha1.c b/sha1.c
index 11be7045..89b32f46 100644
--- a/sha1.c
+++ b/sha1.c
@@ -258,7 +258,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[16], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[16], left_over);
  	}
        ctx->buflen = left_over;
      }
Reviewed-by: Paul Menzel <redacted>


Kind regards,

Paul

Re: [PATCH] Fix potential overlap dest buffer

From: Nigel Croxon <hidden>
Date: 2021-08-18 18:22:13

On 8/18/21 2:34 AM, Paul Menzel wrote:
Dear Nigel,


Am 17.08.21 um 15:14 schrieb Nigel Croxon:
quoted
To meet requirements of Common Criteria certification vulnerablility
vulnerability
quoted
assessment.
That’s only part of a sentence? Is that supposed to be read as a 
continuation of the commit message summary: … to meet requirements …?
Continuation of the commit message. Thanks for catching the
spelling mistake.
quoted
Static code analysis has been run and found the following
error.  Overlapping_buffer: The source buffer potentially overlaps
It’d be great, if you denoted, which tool was run. Maybe even add a 
Found-by tag.
I ran the Coverity scan on the latest build.
https://people.redhat.com/ncroxon/mdadm-4.2-rc2-scan-results.html

quoted
with the destination buffer, which results in undefined
behavior for "memcpy".

The change is to use memmove instead of memcpy.

Signed-off-by: Nigel Croxon <redacted>
---
  sha1.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sha1.c b/sha1.c
index 11be7045..89b32f46 100644
--- a/sha1.c
+++ b/sha1.c
@@ -258,7 +258,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[16], left_over);
+      memmove (ctx->buffer, &ctx->buffer[16], left_over);
      }
        ctx->buflen = left_over;
      }
Reviewed-by: Paul Menzel <redacted>


Kind regards,

Paul

Re: [PATCH] Fix potential overlap dest buffer

From: Jes Sorensen <hidden>
Date: 2021-10-08 15:50:18

On 8/17/21 9:14 AM, Nigel Croxon wrote:
quoted hunk
To meet requirements of Common Criteria certification vulnerablility
assessment. Static code analysis has been run and found the following
error.  Overlapping_buffer: The source buffer potentially overlaps
with the destination buffer, which results in undefined
behavior for "memcpy".

The change is to use memmove instead of memcpy.

Signed-off-by: Nigel Croxon <redacted>
---
 sha1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sha1.c b/sha1.c
index 11be7045..89b32f46 100644
--- a/sha1.c
+++ b/sha1.c
@@ -258,7 +258,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[16], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[16], left_over);
 	}
       ctx->buflen = left_over;
     }
Applied!

Thanks,
Jes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help