[Opensrf-commits] r1809 - trunk/src/libopensrf (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Oct 8 14:26:41 EDT 2009
Author: scottmk
Date: 2009-10-08 14:26:37 -0400 (Thu, 08 Oct 2009)
New Revision: 1809
Modified:
trunk/src/libopensrf/utils.c
Log:
Fix a bug in md5sum() (which only affected code compiled
with debugging turned on).
md5sum() builds an md5 message digest in a buffer. Originally
it used memset() to initialize the buffer with binary zeroes.
At some point the call to memset() was replaced with the
osrf_clearbuf() macro. When compiled in debugging mode,
osrf_clearbuf() fills the buffer with exclamation points;
otherwise it reverts to the original memset().
In this case the use of osrf_clearbuf is inappropriate, because
we use strcat() to build the message digest, two bytes at a
time. We don't need to use memset(), but the first byte needs
to be initialized to a nul byte so that strcat() will work as
intended. Hence:
1. Remove the call to osrf_clearbuf().
2. Put a nul byte at the beginning of the buffer.
Also, I made the buffer smaller. There's no reason for it
to be 256 bytes long.
M src/libopensrf/utils.c
Modified: trunk/src/libopensrf/utils.c
===================================================================
--- trunk/src/libopensrf/utils.c 2009-10-05 18:53:02 UTC (rev 1808)
+++ trunk/src/libopensrf/utils.c 2009-10-08 18:26:37 UTC (rev 1809)
@@ -728,8 +728,8 @@
MD5_stop (&ctx, digest);
char buf[16];
- char final[256];
- osrf_clearbuf(final, sizeof(final));
+ char final[ 1 + 2 * sizeof( digest ) ];
+ final[0] = '\0';
for ( i=0 ; i<16 ; i++ ) {
snprintf(buf, sizeof(buf), "%02x", digest[i]);
More information about the opensrf-commits
mailing list