openssl库函数使用中的SSL_shutdown、SSL_free不能同时使用

openssl库函数中提供了两个销毁ssl连接通道的函数:SSL_shutdown、SSL_free,作用相同,二者取其一,不可同时使用,否则就会出现两次销毁对象的报错。

请看下面一个代码片段:

......

if (SSL_shutdown(ssl) != 1)

{

close(sfd);

printf("ssl shutdown failed\n");

}

SSL_free(ssl);

......

使用-lssl参数编译可以成功,但在运行时,会概率性出现double free or corruption的报错,就是销毁一个已经销毁的对象。详细的报错信息类似于:

[email protected]:/home# ./s

*** glibc detected *** ./s: double free or corruption (!prev): 0x095c0f60 ***

======= Backtrace: =========

/lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0x251ee2]

/lib/i386-linux-gnu/libcrypto.so.1.0.0(CRYPTO_free+0x3a)[0x3bf95a]

/lib/i386-linux-gnu/libcrypto.so.1.0.0(BIO_free+0xe0)[0x430610]

/lib/i386-linux-gnu/libcrypto.so.1.0.0(BIO_free_all+0x34)[0x431194]

/lib/i386-linux-gnu/libssl.so.1.0.0(SSL_set_bio+0x49)[0x889d79]

/lib/i386-linux-gnu/libssl.so.1.0.0(SSL_set_fd+0x57)[0x889f17]

./s[0x8048aee]

/lib/i386-linux-gnu/libpthread.so.0(+0x6d4c)[0xb93d4c]

/lib/i386-linux-gnu/libc.so.6(clone+0x5e)[0x2cbbae]

======= Memory map: ========

00110000-00124000 r-xp 00000000 08:02 4893       /lib/i386-linux-gnu/libz.so.1.2.3.4

00124000-00125000 r--p 00013000 08:02 4893       /lib/i386-linux-gnu/libz.so.1.2.3.4

00125000-00126000 rw-p 00014000 08:02 4893       /lib/i386-linux-gnu/libz.so.1.2.3.4

00126000-00142000 r-xp 00000000 08:02 760        /lib/i386-linux-gnu/libgcc_s.so.1

00142000-00143000 r--p 0001b000 08:02 760        /lib/i386-linux-gnu/libgcc_s.so.1

00143000-00144000 rw-p 0001c000 08:02 760        /lib/i386-linux-gnu/libgcc_s.so.1

001dc000-00380000 r-xp 00000000 08:02 3232       /lib/i386-linux-gnu/libc-2.15.so

00380000-00382000 r--p 001a4000 08:02 3232       /lib/i386-linux-gnu/libc-2.15.so

00382000-00383000 rw-p 001a6000 08:02 3232       /lib/i386-linux-gnu/libc-2.15.so

00383000-00386000 rw-p 00000000 00:00 0

00386000-00519000 r-xp 00000000 08:02 5861       /lib/i386-linux-gnu/libcrypto.so.1.0.0

00519000-00528000 r--p 00193000 08:02 5861       /lib/i386-linux-gnu/libcrypto.so.1.0.0

00528000-0052f000 rw-p 001a2000 08:02 5861       /lib/i386-linux-gnu/libcrypto.so.1.0.0

0052f000-00532000 rw-p 00000000 00:00 0

00759000-0075c000 r-xp 00000000 08:02 3231       /lib/i386-linux-gnu/libdl-2.15.so

0075c000-0075d000 r--p 00002000 08:02 3231       /lib/i386-linux-gnu/libdl-2.15.so

0075d000-0075e000 rw-p 00003000 08:02 3231       /lib/i386-linux-gnu/libdl-2.15.so

00858000-008a9000 r-xp 00000000 08:02 5862       /lib/i386-linux-gnu/libssl.so.1.0.0

008a9000-008ab000 r--p 00051000 08:02 5862       /lib/i386-linux-gnu/libssl.so.1.0.0

008ab000-008af000 rw-p 00053000 08:02 5862       /lib/i386-linux-gnu/libssl.so.1.0.0

00af6000-00b16000 r-xp 00000000 08:02 3222       /lib/i386-linux-gnu/ld-2.15.so

00b16000-00b17000 r--p 0001f000 08:02 3222       /lib/i386-linux-gnu/ld-2.15.so

00b17000-00b18000 rw-p 00020000 08:02 3222       /lib/i386-linux-gnu/ld-2.15.so

00b8d000-00ba4000 r-xp 00000000 08:02 3221       /lib/i386-linux-gnu/libpthread-2.15.so

00ba4000-00ba5000 r--p 00016000 08:02 3221       /lib/i386-linux-gnu/libpthread-2.15.so

00ba5000-00ba6000 rw-p 00017000 08:02 3221       /lib/i386-linux-gnu/libpthread-2.15.so

00ba6000-00ba8000 rw-p 00000000 00:00 0

00fed000-00fee000 r-xp 00000000 00:00 0          [vdso]

08048000-0804a000 r-xp 00000000 08:02 260187     /home/s

0804a000-0804b000 r--p 00001000 08:02 260187     /home/s

0804b000-0804c000 rw-p 00002000 08:02 260187     /home/s

095b3000-095d4000 rw-p 00000000 00:00 0          [heap]

b4c00000-b4c21000 rw-p 00000000 00:00 0

b4c21000-b4d00000 ---p 00000000 00:00 0

b4e00000-b4e21000 rw-p 00000000 00:00 0

b4e21000-b4f00000 ---p 00000000 00:00 0

b4f52000-b4f53000 ---p 00000000 00:00 0

b4f53000-b5753000 rw-p 00000000 00:00 0

b5753000-b5754000 ---p 00000000 00:00 0

b5754000-b5f54000 rw-p 00000000 00:00 0

b5f54000-b5f55000 ---p 00000000 00:00 0

b5f55000-b6755000 rw-p 00000000 00:00 0

b6755000-b6756000 ---p 00000000 00:00 0

b6756000-b6f56000 rw-p 00000000 00:00 0

b6f56000-b6f57000 ---p 00000000 00:00 0

b6f57000-b775a000 rw-p 00000000 00:00 0

b7763000-b7766000 rw-p 00000000 00:00 0

bf89e000-bf8bf000 rw-p 00000000 00:00 0          [stack]

Aborted

这两个函数使用其中任意一个都可以,但不可同时使用。

时间: 2024-07-29 18:09:02

openssl库函数使用中的SSL_shutdown、SSL_free不能同时使用的相关文章

用NDK调用Android手机自带的openssl库函数

目标: 目前很多Android手机已经自带了openssl库, 即libssl.so, libcrypto.so, 以下示例实现了APK通过NDK调用openssl库函数PKCS5_PBKDF2_HMAC(密钥生成算法) 1) 在android工程中创建 jni目录 2) 编辑AbcJni.java package com.example; public class AbcJni { public native byte[] hashKey(byte[] key, byte[] salt, in

SSL探索01

1. OPENSSL简介 OpenSSL项目是一个协作开发一个健壮的,商业级的,全功能的,并且开放源代码工具包,它实现了安全套接字层(SSL v2/v3)和传输层安全(TLS v1)协议以及全强大的通用加密库. 2.使用SSL进行安全IO 使用SSL进行安全IO与原本的socketIO通信区别不大,只是增加了SSL部分内容. 下面说明SSL IO的基本过程: 客户端流程 ① // SSL初始化 ②//socket,connect, ③//ssl,建立SSL连接,SSL_connect(ssl)

windows中wamp环境composer使用中openssl问题解决

今天在windows下学习lavaral,使用composer update命令报如下错误: [Composer\Exception\NoSslException] The openssl extension is required for SSL/TLS protection but is not available. If you can not enable the openssl ex  tension, you can disable this error, at your own r

Https协议:SSL建立过程分析(也比较清楚,而且有OpenSSL的代码)

web访问的两种方式: http协议,我们一般情况下是通过它访问web,因为它不要求太多的安全机制,使用起来也简单,很多web站点也只支持这种方式下的访问. https协议(Hypertext Transfer Protocol over Secure Socket Layer),对于安全性要求比较高的情况,可以通过它访问web,比如工商银行https://www.icbc.com.cn/icbc/(当然也可以通过http协议访问,只是没那么安全了).其安全基础是SSL协议. SSL协议,当前版

OpenSSL 结构体

1.X509_STORE 头文件:x509_vfy.h 定义 typedef struct x509_store_st X509_STORE; struct x509_store_st { /* The following is a cache of trusted certs */ int cache; /* if true, stash any hits */ STACK_OF(X509_OBJECT) *objs; /* Cache of all objects */ /* These a

基于X.509证书和SSL协议的身份认证过程实现(OpenSSL可以自己产生证书,有TCP通过SSL进行实际安全通讯的实际编程代码)good

上周帮一个童鞋做一个数字认证的实验,要求是编程实现一个基于X.509证书认证的过程,唉!可怜我那点薄弱的计算机网络安全的知识啊!只得恶补一下了. 首先来看看什么是X.509.所谓X.509其实是一种非常通用的证书,什么是证书?唉!这么说吧!当两个人需要进行远程通信而又不想让第三个人知道时就必须建立一种安全措施,因为看不到对方的脸,又不能通过电话直接询问对方,就得想点别的办法,比如我设计一个密码,让后发短信告诉你,这样当我们在网上交流之前就可以对一下密码,暗号之类的.确认后就可以证明你的身份了.这

基于openssl的单向和双向认证

1.前言 最近工作涉及到https,需要修改nginx的openssl模块,引入keyless方案.关于keyless可以参考CloudFlare的官方博客: https://blog.cloudflare.com/keyless-ssl-the-nitty-gritty-technical-details/?utm_source=tuicool&utm_medium=referral. 在openssl的基础上修改私钥校验过程,因此需要对openssl的认证认证流程需要熟悉一下.SSL中涉及到

linux openssl 编程 Client端

相关配置等请參看上一篇关于server端文章:http://blog.csdn.net/pingd/article/details/47805349 1.Client端源代码: openssl_client.c #include <stdio.h> #include <string.h> #include <errno.h> #include <sys/socket.h> #include <resolv.h> #include <stdl

安全通信系统--OpenSSL服务器和客户端

环境配置 SSL的初始化 这一步主要使用OpenSSL提供的函数设置算法.证书等,一般步骤都固定了的,初始化流程示意图如下所示: SSL初始化流程图 主要代码为: [cpp] view plain copy print? SSL_load_error_strings(); /*为打印调试信息作准备*/ OpenSSL_add_ssl_algorithms(); /*初始化*/ //meth = TLSv1_server_method(); /*采用什么协议(SSLv2/SSLv3/TLSv1)在