Conversation
Coverity found the following test where memcpy is used to copy an overlapping buffer. 'memmove' should be used instead. Error: BUFFER_SIZE (CWE-474): libmspack-0.10.1alpha/test/md5.c:281: overlapping_buffer: The source buffer "&ctx->buffer[64]" potentially overlaps with the destination buffer "ctx->buffer", which results in undefined behavior for "memcpy". libmspack-0.10.1alpha/test/md5.c:281: remediation: Use memmove instead of "memcpy". 279| md5_process_block (ctx->buffer, 64, ctx); 280| left_over -= 64; 281|-> memcpy (ctx->buffer, &ctx->buffer[64], left_over); 282| } 283| ctx->buflen = left_over; Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
|
Hey @kyz, just wanted to follow up to see if there are any plans to move this forward? We'd really like to see this fix upstream. Anything blocking this PR merge? |
|
I wanted to check the logic for myself as this looks like a code linter's suggestion. The linter could be right, or not. This is my reading of the logic:
So I don't think the memmove is needed. Do you agree, or do you think I've missed something? To add to that, this source file was copied verbatim from glibc and has been in use since 1995. I would've expected to see this issue raised sooner, against glibc itself, if this memcpy() overlapped. glibc 2.39 removed libcrypt and recommended using libxcrypt, whose md5 function has a different implementation but similar memcpy logic Neither the libxcrypt MD5 implementation, nor the old glibc one currently in use, are as fast as they can be, and checksumming takes a large portion of the CPU time for |
|
This seems a reasonable explanation, so we can close this. Unfortunately Coverity is going to keep moaning about this. You'd be within your rights to ignore that because it's not your problem (it's closed source software after all). But a couple of things that might be done to avoid that would be either: just use memmove anyway, or annotate the line by adding this above the line containing the memcpy: |
Coverity found the following test where
memcpyis used to copy an overlapping buffer.memmoveshould be used instead.