【问题标题】:OpenSSL in a VisualC++ DLLVisualC++ DLL 中的 OpenSSL
【发布时间】:2016-04-18 21:50:37
【问题描述】:

我正在尝试编写一个 C++ DLL,它使用 openSSL 来保护与服务器的连接。

我对这段代码感到非常困惑

#include "stdafx.h"
#include <string.h>
#include <iostream>
//SSL stuff
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/x509.h>
#include <openssl/x509_vfy.h>
#include <openssl/ossl_typ.h>
#include <openssl/applink.c>
//Winsock stuf
#pragma comment(lib, "ws2_32.lib")
{... Create a method in which we set up the SSL connection ...}
char* tSend = "{\"reqtype\":\"keyexchange\"}";
int sendSize = strlen(tSend);
int net_tSend = htonl(sendSize);
SSL_write(ssl, &net_tSend, 4);
SSL_write(ssl, tSend, sendSize);

在控制台应用程序中工作正常,但在我的 DLL 中崩溃。 这是我的例外:

TestsForPKCSDLL.exe 中的 0x00007FF865207DA0 (libeay32.dll) 引发异常:0xC0000005:访问冲突读取位置 0x0000000000000000。

非常感谢您的宝贵时间。

【问题讨论】:

  • 调试器告诉你什么?
  • 访问接近 0 的地址时发生 AccessViolation 意味着正在访问 NULL 指针。在代码中找到 NULL 指针并修复它。最有可能的罪魁祸首是您的 ssl 指针,或者链接到的 SSL_CTXBIO
  • 这个问题到底是什么(除了你很困惑之外)?
  • @Dan:我引用的消息(抛出异常......)。
  • @jww:好吧,当然是如何让它工作了。

标签: c++ dll openssl winsock winsock2


【解决方案1】:

经过一番研究,问题似乎出在 htonl() 函数上。

    u_long mylong = 10L;
    int net_tSend = htonl(mylong);

TestsForPKCSDLL.exe 中的 0x00007FF863807DA0 (libeay32.dll) 引发异常:0xC0000005:访问冲突读取位置 0x0000000000000000。

显然没有正确加载。我认为,因为我的代码在 DLL 中,如果调用程序不引用 SSL dll,它会崩溃。我会尝试静态链接 libeay32 和 ssleay32 看看是否可行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-13
    • 1970-01-01
    • 2018-05-12
    • 2020-07-19
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 2013-03-29
    相关资源
    最近更新 更多