I have a function get_digest() which sometimes causes a segmentation
fault, and I cannot figure out why.  I use the function in two programs,
in the first one it works fine, but in the second it segfaults.  The
strange thing is that it segfaults on the EVP_DigestInit_ex() function,
before the variables passed in are even considered.  

Here is the function:
u_char *get_digest(u_char *data, int length, int *outlen)
{
  EVP_MD_CTX mdctx;
  const EVP_MD *md = EVP_sha1();
  int digest_size = EVP_MD_size(md);
  u_char *digest;

  EVP_MD_CTX_init(&mdctx);
  EVP_DigestInit_ex(&mdctx, md, NULL); /* Segfault happens here */
  EVP_DigestUpdate(&mdctx, data, length);
  
  digest = malloc(digest_size);
  EVP_DigestFinal_ex(&mdctx, digest, outlen);
  EVP_MD_CTX_cleanup(&mdctx);
  return digest;
}

Here is a (partial) backtrace
#0  0x4108ae47 in mallopt () from /lib/libc.so.6
#1  0x41089e03 in malloc () from /lib/libc.so.6
#2  0x4008eb9b in CRYPTO_get_mem_debug_options ()
   from /usr/lib/i686/cmov/libcrypto.so.0.9.7
#3  0x00000064 in ?? ()
#4  0x41016c20 in ?? () from /lib/ld-linux.so.2
#5  0x4000019c in ?? ()
#6  0x4008eb85 in CRYPTO_get_mem_debug_options ()
   from /usr/lib/i686/cmov/libcrypto.so.0.9.7
#7  0x4014f0c0 in ?? () from /usr/lib/i686/cmov/libcrypto.so.0.9.7
#8  0x4006c8f8 in ?? () from /usr/lib/i686/cmov/libcrypto.so.0.9.7
#9  0x40061278 in ?? ()
#10 0x41016c20 in ?? () from /lib/ld-linux.so.2

Does anyone know what could be causing this segfault?
Ben
-- 
Ben <[EMAIL PROTECTED]>

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to