This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Obvious fix for libiberty/md5.c


Hi Guys,

  I hope that the following patch counts as obvious:  The
  md5_process_bytes() routine in libiberty/md5.c uses the return value
  of the memcpy() function, but under certain circumstances memcpy can
  be aliased to bcopy() and bcopy does not have a return value.

  The fix is to call memcpy first and then to refer to the destination
  buffer pointer explicitly in the following call to
  md5_process_block().  Like this:

Index: libiberty/md5.c
===================================================================
RCS file: /cvs/src/src/libiberty/md5.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 md5.c
*** libiberty/md5.c	3 Jul 2005 19:16:19 -0000	1.9
--- libiberty/md5.c	11 Mar 2008 13:57:34 -0000
*************** md5_process_bytes (const void *buffer, s
*** 234,240 ****
        if (UNALIGNED_P (buffer))
          while (len > 64)
            {
!             md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
              buffer = (const char *) buffer + 64;
              len -= 64;
            }
--- 234,241 ----
        if (UNALIGNED_P (buffer))
          while (len > 64)
            {
! 	    memcpy (ctx->buffer, buffer, 64);
!             md5_process_block (ctx->buffer, 64, ctx);
              buffer = (const char *) buffer + 64;
              len -= 64;
            }


  I assume that this is OK to apply as an obvious fix.

Cheers
  Nick

libiberty/ChangeLog
2008-03-11  Nick Clifton  <nickc@redhat.com>

	* md5.c (md5_process_bytes): Do not assume that memcpy will
	provide a return value.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]