Skip to content

Fix memory leaks and improve error handling in req() function #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1664,40 +1664,41 @@ void KeyAuth::api::setDebug(bool value) {
KeyAuth::api::debug = value;
}

std::string KeyAuth::api::req(std::string data, std::string url) {
std::string KeyAuth::api::req(const std::string& data, const std::string& url) {

CURL* curl = curl_easy_init();
if (!curl)
return XorStr("null");
if (!curl) {
error(XorStr("CURL Initialization Failed!"));
}

std::string to_return;
std::string headers;

// Set CURL options
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1);

curl_easy_setopt(curl, CURLOPT_NOPROXY, XorStr( "keyauth.win" ) );

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);

curl_easy_setopt(curl, CURLOPT_NOPROXY, XorStr("keyauth.win").c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &to_return);

curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &headers);

auto code = curl_easy_perform(curl);

if (code != CURLE_OK)
error(curl_easy_strerror(code));
// Perform the request
CURLcode code = curl_easy_perform(curl);
if (code != CURLE_OK) {
std::string errorMsg = "CURL Error: " + std::string(curl_easy_strerror(code));
curl_easy_cleanup(curl);
error(errorMsg);
}

debugInfo(data, url, to_return, "Sig: " + signature + "\nTimestamp:" + signatureTimestamp);

curl_easy_cleanup(curl);
return to_return;
}

void error(std::string message) {
system((XorStr("start cmd /C \"color b && title Error && echo ").c_str() + message + XorStr(" && timeout /t 5\"")).c_str());
LI_FN(__fastfail)(0);
Expand Down
6 changes: 2 additions & 4 deletions auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,10 @@ namespace KeyAuth {
responsedata response;
Tfa tfa;
private:
std::string sessionid, enckey;

static std::string req(std::string data, std::string url);

std::string sessionid, enckey;
static std::string req(const std::string& data, const std::string& url);
static void debugInfo(std::string data, std::string url, std::string response, std::string headers);

static void setDebug(bool value);


Expand Down