Skip to content
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

Segfault in Session::prepareCommonShared with proxy authentication #1180

Open
simue opened this issue Feb 14, 2025 · 2 comments
Open

Segfault in Session::prepareCommonShared with proxy authentication #1180

simue opened this issue Feb 14, 2025 · 2 comments

Comments

@simue
Copy link
Contributor

simue commented Feb 14, 2025

Description

I get a segfault with the following call stack:

libc.so.6![Unknown/Just-In-Time compiled code] (Unknown Source:0)
Curl_setstropt(char ** charp, const char * s) (\home\user\.conan2\p\b\libcu0c6ab0202663c\b\src\lib\setopt.c:68)
Curl_vsetopt(struct Curl_easy * data, CURLoption option, va_list param) (\home\user\.conan2\p\b\libcu0c6ab0202663c\b\src\lib\setopt.c:1604)
curl_easy_setopt(struct Curl_easy * data, CURLoption tag) (\home\user\.conan2\p\b\libcu0c6ab0202663c\b\src\lib\setopt.c:3171)
cpr::Session::prepareCommonShared(cpr::Session * const this) (\home\user\repos\tmp\cpr\cpr\session.cpp:184)
cpr::Session::prepareCommon(cpr::Session * const this) (\home\user\repos\tmp\cpr\cpr\session.cpp:226)
cpr::Session::PreparePost(cpr::Session * const this) (\home\user\repos\tmp\cpr\cpr\session.cpp:860)
cpr::Session::Post(cpr::Session * const this) (\home\user\repos\tmp\cpr\cpr\session.cpp:748)
[...]

This happens when a proxy is set, along with proxy authentication.
Setting the proxy authentication manually in session.cpp resolved the issue for me:

    // Proxy:
    const std::string protocol = url_.str().substr(0, url_.str().find(':'));
    if (proxies_.has(protocol)) {
        curl_easy_setopt(curl_->handle, CURLOPT_PROXY, proxies_[protocol].c_str());
        if (proxyAuth_.has(protocol)) {
            // this worked:
            //  std::string username = "user";
            //  std::string password = "password";
            //  curl_easy_setopt(curl_->handle, CURLOPT_PROXYUSERNAME, username.c_str());
            //  curl_easy_setopt(curl_->handle, CURLOPT_PROXYPASSWORD, password.c_str());
            // this does trigger the segfault (original code):
            curl_easy_setopt(curl_->handle, CURLOPT_PROXYUSERNAME, proxyAuth_.GetUsername(protocol));
            curl_easy_setopt(curl_->handle, CURLOPT_PROXYPASSWORD, proxyAuth_.GetPassword(protocol));
        }
    }

Example/How to Reproduce

  1. Create a cpr::Session
  2. Set proxy with proxy authentication
  3. Perform POST
  4. Segfault

Possible Fix

I didn't look into that, yet

Where did you get it from?

GitHub (branch e.g. master)

Additional Context/Your Environment

  • OS: Linux
  • Version: custom kernel 5.15
@COM8
Copy link
Member

COM8 commented Feb 14, 2025

@simue thanks for reporting.
Could you please create a small example application for me to reproduce this?

@simue
Copy link
Contributor Author

simue commented Feb 14, 2025

#1181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants