1

我正在使用一个用于 base 64 编码的函数,但在 BIO_free_all() 中得到了一个 SIGABRT。

功能 :

char *base64(const unsigned char *input, int length)
{
   BIO *bmem, *b64;
   BUF_MEM *bptr;
   char *buff;
   b64 = BIO_new(BIO_f_base64());
   bmem = BIO_new(BIO_s_mem());
   b64 = BIO_push(b64, bmem);
   BIO_write(b64, input, length);
   BIO_flush(b64);
   BIO_get_mem_ptr(b64, &bptr);
   buff = (char *)malloc(bptr->length);
   memcpy(buff, bptr->data, bptr->length-1);
   buff[bptr->length-1] = 0;

   BIO_free_all(b64);

   return buff;
   };

主循环中的函数调用:

unsigned char hash [20];
SHA1(key,strlen(key),hash);
h_part2= base64(hash, sizeof(hash));

在 gdb 中回溯时显示错误:

  0  0xb7fdd424 in __kernel_vsyscall ()
  1  0xb7ca11ef in raise () from /lib/i386-linux-gnu/libc.so.6
  2  0xb7ca4835 in abort () from /lib/i386-linux-gnu/libc.so.6
  3  0xb7cdc2fa in ?? () from /lib/i386-linux-gnu/libc.so.6
  4  0xb7ce6e42 in ?? () from /lib/i386-linux-gnu/libc.so.6
  5  0xb7e518da in CRYPTO_free () from /lib/i386-linux-gnu/libcrypto.so.1.0.0
  6  0xb7ec1a0f in BUF_MEM_free () from /lib/i386-linux-gnu/libcrypto.so.1.0.0
  7  0xb7ec370c in ?? () from /lib/i386-linux-gnu/libcrypto.so.1.0.0
  8  0xb7ec22b8 in BIO_free () from /lib/i386-linux-gnu/libcrypto.so.1.0.0
  9  0xb7ec2e44 in BIO_free_all () from /lib/i386-linux-gnu/libcrypto.so.1.0.0
  10 0x08058024 in base64 (input=0xbffff0f8 "\312", <incomplete sequence \375\265>, length=20)
at socket.c:121
4

0 回答 0