From: scottmk Date: Thu, 8 Oct 2009 18:26:37 +0000 (+0000) Subject: Fix a bug in md5sum() (which only affected code compiled X-Git-Tag: osrf_rel_2_0_1~277 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ad9c44f31e402b8376bcbd75188e4762b134ab0a;p=OpenSRF.git 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 git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1809 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/libopensrf/utils.c b/src/libopensrf/utils.c index 79e6d0f..a3ca2ab 100644 --- a/src/libopensrf/utils.c +++ b/src/libopensrf/utils.c @@ -728,8 +728,8 @@ char* md5sum( const char* text, ... ) { 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]);