[tool_parsecfg]: expand tilde-charaters in parameters

Tilde-characters in both quoted and unquoted strings
will be expanded to the users home-directory.

Fixes #2317
This commit is contained in:
Max Bossing 2025-08-09 14:52:41 +02:00
parent fe5225b5ea
commit 0efea2edfd
No known key found for this signature in database
GPG key ID: E2E95E80A0C1217E

View file

@ -206,7 +206,32 @@ int parseconfig(const char *filename)
#ifdef DEBUG_CONFIG
fprintf(tool_stderr, "PARAM: \"%s\"\n",(param ? param : "(null)"));
#endif
/* expand tilde-characters to the users home directory */
if(param && param[0] == '~') {
const char *home = curl_getenv("HOME");
if(home) {
char *tparam = strdup(param + 1);
if(!tparam) {
rc = 1; /* out of memory */
break;
}
curlx_dyn_reset(&pbuf);
if(curlx_dyn_add(&pbuf, home)) {
rc = 1; /* out of memory */
break;
}
if(curlx_dyn_add(&pbuf, tparam)) {
rc = 1; /* out of memory */
break;
}
free(tparam);
param = curlx_dyn_ptr(&pbuf);
}
}
res = getparameter(option, param, &usedarg, config);
config = global->last;
if(!res && param && *param && !usedarg)