Skip to content

curl_url_get() with CURLU_URLENCODE returns CURLUE_OK and NULL for an empty part #23659

Closed

Description

@urazoff

I did this

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURLU *u = curl_url();
  char *user = NULL;
  CURLUcode rc;

  curl_url_set(u, CURLUPART_URL, "https://@example.com/", 0);
  rc = curl_url_get(u, CURLUPART_USER, &user, CURLU_URLENCODE);
  printf("rc=%d user=%s\n", rc, user ? user : "(null)");
  return 0;
}
rc=0 user=(null)

Without CURLU_URLENCODE the same call also returns CURLUE_OK, but sets user to an allocated empty string. The same happens for an empty password (https://user:@example.com/) and, with CURLU_GET_EMPTY, for an empty query (https://example.com/?) and fragment (https://example.com/#).

Reported by Dilshod Urazov (GenProof)

I expected the following

CURLUE_OK with *content set to an allocated "", since the man page says content gets "updated to point to a newly allocated string with the contents". Code that uses the string after CURLUE_OK dereferences NULL.

curl/libcurl version

libcurl 8.23.0 and master 25f035e

operating system

24.6.0 Darwin Kernel Version 24.6.0: Wed Nov 5 21:34:00 PST 2025; root:xnu-11417.140.69.705.2~1/RELEASE_ARM64_T8132 arm64

Activity

  1. self-assigned this
    on Oct 28, 2026
  2. added a commit that references this issue on Oct 29, 2026
    2bc7802
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions