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

setopt: make the setstropt_userpwd args compulsory #13608

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 16 additions & 20 deletions lib/setopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,38 +115,34 @@ static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp)
char *user = NULL;
char *passwd = NULL;

DEBUGASSERT(userp);
DEBUGASSERT(passwdp);

/* Parse the login details if specified. It not then we treat NULL as a hint
to clear the existing data */
if(option) {
size_t len = strlen(option);
if(len > CURL_MAX_INPUT_LENGTH)
return CURLE_BAD_FUNCTION_ARGUMENT;

result = Curl_parse_login_details(option, len,
(userp ? &user : NULL),
(passwdp ? &passwd : NULL),
NULL);
result = Curl_parse_login_details(option, len, &user, &passwd, NULL);
}

if(!result) {
/* Store the username part of option if required */
if(userp) {
if(!user && option && option[0] == ':') {
/* Allocate an empty string instead of returning NULL as user name */
user = strdup("");
if(!user)
result = CURLE_OUT_OF_MEMORY;
}

Curl_safefree(*userp);
*userp = user;
/* Store the username part */
if(!user && option && option[0] == ':') {
/* Allocate an empty string instead of returning NULL as user name */
user = strdup("");
if(!user)
result = CURLE_OUT_OF_MEMORY;
}

/* Store the password part of option if required */
if(passwdp) {
Curl_safefree(*passwdp);
*passwdp = passwd;
}
Curl_safefree(*userp);
*userp = user;

/* Store the password part */
Curl_safefree(*passwdp);
*passwdp = passwd;
}

return result;
Expand Down
Loading