Skip to content

Commit

Permalink
fixup a config file specified with CURL_RC needs to exist
Browse files Browse the repository at this point in the history
... or cause an error
  • Loading branch information
bagder committed Apr 15, 2024
1 parent f44badd commit 4968632
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2721,10 +2721,14 @@ CURLcode operate(struct GlobalConfig *global, int argc, argv_item_t argv[])
!strcmp(first_arg, "--verbose"))) {
configdebug = TRUE;
}
parseconfig(curlrc, global); /* ignore possible failure */
if(parseconfig(curlrc, global)) {
if(curlrc)
errorf(global, "The config file provided in CURL_RC trigged an error");
result = CURLE_FAILED_INIT;
}

/* If we had no arguments then make sure a url was specified in .curlrc */
if((argc < 2) && (!global->first->url_list)) {
else if((argc < 2) && (!global->first->url_list)) {
helpf(tool_stderr, NULL);
result = CURLE_FAILED_INIT;
}
Expand Down
10 changes: 7 additions & 3 deletions src/tool_parsecfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
#endif
}
else {
if(strcmp(filename, "-"))
if(strcmp(filename, "-")) {
file = fopen(filename, FOPEN_READTEXT);

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This argument to a file access function is derived from
user input (a command-line argument)
and then passed to fopen(__filename).
This argument to a file access function is derived from
user input (an environment variable)
and then passed to fopen(__filename).

if(!file) {
msgf(global, "config: ", "could not read '%s'", filename);
rc = 1;
}
}
else
file = stdin;
}
Expand Down Expand Up @@ -294,8 +300,6 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
if(fileerror)
rc = 1;
}
else
rc = 1; /* couldn't open the file */

free(pathalloc);
return rc;
Expand Down

0 comments on commit 4968632

Please sign in to comment.