gpt4 book ai didi

c++ - valgrind 在使用 https 时报告 libcurl 的问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:29:07 25 4
gpt4 key购买 nike

所以我有一个通过 https 与 facebook 服务器通信的非常基本的示例,但 valgrind 正在提示。所以我假设我没有设置错误...有人知道我做错了什么吗?

这是我的代码:

#include <string>
#include <iostream>
#include <curl/curl.h>

size_t write_fn_impl( void* ptr, size_t size, size_t nmemb, void * data )
{
std::string * result = static_cast<std::string*>(data);
*result += std::string( (char*)ptr, size*nmemb );
return size*nmemb;
}

int main()
{
std::string url_full="https://graph.facebook.com/me";
std::string useragent = "Facebook API C++ Client (curl)";

CURL * ch_ = curl_easy_init();
char error_buffer[CURL_ERROR_SIZE];
curl_easy_setopt( ch_, CURLOPT_ERRORBUFFER, error_buffer );
curl_easy_setopt( ch_, CURLOPT_WRITEFUNCTION, &write_fn_impl );
std::string result;
curl_easy_setopt( ch_, CURLOPT_WRITEDATA, &result );
int id = 1;
curl_easy_setopt( ch_, CURLOPT_VERBOSE, id );

curl_easy_setopt( ch_, CURLOPT_URL, url_full.c_str() );
curl_easy_setopt( ch_, CURLOPT_USERAGENT, useragent.c_str() );
curl_easy_setopt( ch_, CURLOPT_CONNECTTIMEOUT, 10);
curl_easy_setopt( ch_, CURLOPT_TIMEOUT, 30);
curl_easy_perform(ch_);
curl_easy_cleanup(ch_);

std::cout<< result<<std::endl;
}

valgrind 说的是:

==14149== Memcheck, a memory error detector
==14149== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==14149== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info
==14149== Command: ./a.out
==14149==
* About to connect() to graph.facebook.com port 443 (#0)
* Trying 66.220.146.47... * connected
* Connected to graph.facebook.com (66.220.146.47) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
==14149== Syscall param write(buf) points to uninitialised byte(s)
==14149== at 0x4268113: __write_nocancel (in /lib/tls/i686/cmov/libc-2.10.1.so)
==14149== by 0x44A5A8E: BIO_write (in /lib/i686/cmov/libcrypto.so.0.9.8)
==14149== by 0x43E49B8: ssl23_write_bytes (in /lib/i686/cmov/libssl.so.0.9.8)
==14149== by 0x43E39AB: ssl23_connect (in /lib/i686/cmov/libssl.so.0.9.8)
==14149== by 0x43F0D49: SSL_connect (in /lib/i686/cmov/libssl.so.0.9.8)
==14149== by 0x4050EB0: ossl_connect_common (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x4052202: Curl_ossl_connect (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x406597F: Curl_ssl_connect (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x403FF1B: Curl_http_connect (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x4046F6D: Curl_protocol_connect (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x404C396: Curl_connect (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x4059B23: Curl_perform (in /usr/lib/libcurl.so.4.1.1)
==14149== Address 0x47e92df is 15 bytes inside a block of size 21,848 alloc'd
==14149== at 0x4024C1C: malloc (vg_replace_malloc.c:195)
==14149== by 0x4446EFD: ??? (in /lib/i686/cmov/libcrypto.so.0.9.8)
==14149== by 0x444755B: CRYPTO_malloc (in /lib/i686/cmov/libcrypto.so.0.9.8)
==14149== by 0x44A4EF7: BUF_MEM_grow (in /lib/i686/cmov/libcrypto.so.0.9.8)
==14149== by 0x43E3BAB: ssl23_connect (in /lib/i686/cmov/libssl.so.0.9.8)
==14149== by 0x43F0D49: SSL_connect (in /lib/i686/cmov/libssl.so.0.9.8)
==14149== by 0x4050EB0: ossl_connect_common (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x4052202: Curl_ossl_connect (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x406597F: Curl_ssl_connect (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x403FF1B: Curl_http_connect (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x4046F6D: Curl_protocol_connect (in /usr/lib/libcurl.so.4.1.1)
==14149== by 0x404C396: Curl_connect (in /usr/lib/libcurl.so.4.1.1)

还有更多页面....

最佳答案

MK 部分正确。 Valgrind 确实抛出了很多关于 OpenSSL 的垃圾警告。但就我而言,我看到的崩溃似乎确实是由于我使用 openSSL 的方式出现了一些问题。特别是它没有为多线程使用正确设置。 curl 文档涵盖了您需要做的事情......但不知何故我一定错过了它)

无论如何,这是帮助我找到它的抑制文件..它可能对某人有用..但要注意它可能不会捕获您想要捕获的所有内容,它可能会捕获一些您不想要的东西.. .

{
openssl-rand-write
Memcheck:Param
write(buf)
fun:__write_nocancel
fun:BIO_write
fun:ssl23_write_bytes
fun:ssl23_connect
fun:SSL_connect
fun:ossl_connect_common
}
{
openssl-rand-write2
Memcheck:Param
write(buf)
fun:__write_nocancel
fun:BIO_write
fun:ssl3_write_pending
obj:/lib/i686/cmov/libssl.so.0.9.8
fun:ssl3_write_bytes
fun:ssl3_write
fun:SSL_write
}
{
openssl-rand-write3
Memcheck:Param
write(buf)
fun:__write_nocancel
fun:BIO_write
...
fun:ossl_connect_common
}
{
openssl-rand-uninit_mod_inverse
Memcheck:Cond
fun:BN_mod_inverse
...
obj:/lib/i686/cmov/libcrypto.so.0.9.8
}
{
openssl-rand-uninit_div
Memcheck:Cond
fun:BN_div
...
obj:/lib/i686/cmov/libcrypto.so.0.9.8
}
{
openssl-uninit-padding
Memcheck:Cond
fun:RSA_padding_add_PKCS1_type_2
obj:/lib/i686/cmov/libcrypto.so.0.9.8
}
{
openssl-uninit-ucmp
Memcheck:Cond
fun:BN_ucmp
obj:/lib/i686/cmov/libcrypto.so.0.9.8
}
{
openssl-uninit-encrypt
Memcheck:Cond
obj:/lib/i686/cmov/libcrypto.so.0.9.8
fun:RSA_public_encrypt
}
{
openssl-uninit-ssl3_read_bytes
Memcheck:Cond
fun:ssl3_read_bytes
fun:ssl3_read
fun:SSL_read
}
{
openssl-uninit-get_finished
Memcheck:Cond
fun:ssl3_get_finished
fun:ssl3_connect
fun:SSL_connect
fun:ossl_connect_common
}
{
openssl-uninit-read_bytes
Memcheck:Cond
...
fun:ossl_connect_common
}
{
openssl-value4-connect_common
Memcheck:Value4
...
fun:ossl_connect_common
}
{
openssl-uninit-encrypt
Memcheck:Cond
...
fun:RSA_public_encrypt
}

关于c++ - valgrind 在使用 https 时报告 libcurl 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4870601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com