Re: segmentation fault with libcrypto.so (but not libcrypto.a)
Since people didn't like the previous code, try the following version with safer memory handling. It still segfaults when using the shared library and doesn't when using the static one. Replacing the line above with the commented out line works in both cases (since we're no longer relying on SHA1 to allocate the memory for the return result for us).
#include <openssl/hmac.h>
#include <stdio.h>
int main(int argc, char** argv) {
unsigned char foo[10] = "boo";
unsigned char* res = malloc(20);
unsigned char* res2 = res;
res = SHA1(foo, 3, 0);
//res = SHA1(foo, 3, res);
int i;
for(i = 0; i < 20; i++)
printf("%x ", res[i]);
printf("\n");
free(res2);
}
Reply to: