From 0efea2edfdf4808d41ed23c614f7bbdf637c8074 Mon Sep 17 00:00:00 2001 From: Max Bossing Date: Sat, 9 Aug 2025 14:52:41 +0200 Subject: [PATCH] [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 --- src/tool_parsecfg.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c index bc22b9d5b7..555414e007 100644 --- a/src/tool_parsecfg.c +++ b/src/tool_parsecfg.c @@ -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)