Like when trying to import an environment variable that does not exist.
Also fix a bug for reading env variables when there is a default value
set.
Bug: https://curl.se/mail/archive-2024-02/0008.html
Reported-by: Brett Buddin
Add test 462 to verify.
Closes #12862
int lineno = 0;
bool dashed_option;
struct curlx_dynbuf buf;
- bool fileerror;
+ bool fileerror = FALSE;
curlx_dyn_init(&buf, MAX_CONFIG_LINE_LENGTH);
DEBUGASSERT(filename);
- while(my_get_line(file, &buf, &fileerror)) {
+ while(!rc && my_get_line(file, &buf, &fileerror)) {
int res;
bool alloced_param = FALSE;
lineno++;
res != PARAM_VERSION_INFO_REQUESTED &&
res != PARAM_ENGINES_REQUESTED) {
const char *reason = param2text(res);
- warnf(operation->global, "%s:%d: warning: '%s' %s",
- filename, lineno, option, reason);
+ errorf(operation->global, "%s:%d: '%s' %s",
+ filename, lineno, option, reason);
+ rc = res;
}
}
#include "memdebug.h" /* keep this as LAST include */
#define MAX_EXPAND_CONTENT 10000000
+#define MAX_VAR_LEN 128 /* max length of a name */
static char *Memdup(const char *data, size_t len)
{
line = &envp[2];
}
else if(envp) {
- char name[128];
+ char name[MAX_VAR_LEN];
size_t nlen;
size_t i;
char *funcp;
ParameterError err = PARAM_OK;
bool import = FALSE;
char *ge = NULL;
+ char buf[MAX_VAR_LEN];
if(*input == '%') {
import = TRUE;
while(*line && (ISALNUM(*line) || (*line == '_')))
line++;
nlen = line - name;
- if(!nlen || (nlen > 128)) {
+ if(!nlen || (nlen >= MAX_VAR_LEN)) {
warnf(global, "Bad variable name length (%zd), skipping", nlen);
return PARAM_OK;
}
if(import) {
- ge = curl_getenv(name);
+ /* this does not use curl_getenv() because we want "" support for blank
+ content */
+ if(*line) {
+ /* if there is a default action, we need to copy the name */
+ memcpy(buf, name, nlen);
+ buf[nlen] = 0;
+ name = buf;
+ }
+ ge = getenv(name);
if(!*line && !ge) {
/* no assign, no variable, fail */
errorf(global, "Variable '%s' import fail, not set", name);
if(contalloc)
free(content);
}
- curl_free(ge);
return err;
}
test435 test436 test437 test438 test439 test440 test441 test442 test443 \
test444 test445 test446 test447 test448 test449 test450 test451 test452 \
test453 test454 test455 test456 test457 test458 test459 test460 test461 \
+test462 \
\
test490 test491 test492 test493 test494 test495 test496 test497 test498 \
test499 test500 test501 test502 test503 test504 test505 test506 test507 \
--- /dev/null
+<testcase>
+<info>
+<keywords>
+variables
+--config
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+none
+</server>
+<name>
+Missing environment variables in config file
+</name>
+<file name="%LOGDIR/cmd">
+variable %MISSING
+expand-data {{MISSING}}
+</file>
+<command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER -K %LOGDIR/cmd
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<errorcode>
+26
+</errorcode>
+</verify>
+</testcase>