Skip to content

NULL deref when netrc is enabled #17659

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

Closed
wants to merge 3 commits into from
Closed

NULL deref when netrc is enabled #17659

wants to merge 3 commits into from

Conversation

z2-2z
Copy link
Contributor

@z2-2z z2-2z commented Jun 18, 2025

A NULL deref exists in lib/url.c that can be triggered when netrc is enabled and a specially crafted netrc-file is given to libcurl.
The bug is in line 2830:

NETRCcode ret = Curl_parsenetrc(&data->state.netrc, conn->host.name,
                                      userp, passwdp,
                                      data->set.str[STRING_NETRC_FILE]);

// ...

if(str_has_ctrl(*userp) || str_has_ctrl(*passwdp)) {

  // ...

}

There is a path through Curl_parsenetrc that returns NETRC_OK but leaves *userp as NULL and only sets *passwdp, which then later triggers a NULL-deref in str_has_ctrl(*userp).

To reproduce this, use this netrc file and the following client:

#include "curl/curl.h"

int main (int argc, char** argv) {
    CURL* curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, "ftp://127.0.0.1/");
    curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
    curl_easy_setopt(curl, CURLOPT_NETRC_FILE, "<attached-file>");
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
}

@testclutch

This comment was marked as outdated.

@bagder bagder closed this in f9548bf Jun 20, 2025
bagder added a commit that referenced this pull request Jun 20, 2025
@bagder
Copy link
Member

bagder commented Jun 20, 2025

Thanks!

denandz pushed a commit to denandz/curl that referenced this pull request Jun 21, 2025
denandz pushed a commit to denandz/curl that referenced this pull request Jun 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants