mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
Forbid % character in parameters.
This character causes problems in C and in the shell if we try to output it in an error message. Forbid it completely and spell it out in error messages to avoid strange effects. There is likely a better way deal with the issue but this will do for now.
This commit is contained in:
parent
6be9c7b63a
commit
f01aa5861d
@ -485,6 +485,14 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
|
||||
if (commandParamList == NULL)
|
||||
commandParamList = strLstNew();
|
||||
|
||||
// Forbid parameters that contain % since they cause chaos downstream. Even printing % seems to cause
|
||||
// problems in the shell so spell it out instead.
|
||||
if (strchr(argList[optind - 1], '%') != NULL)
|
||||
{
|
||||
THROW_FMT(
|
||||
ParamInvalidError, "invalid percent character in parameter %u", strLstSize(commandParamList) + 1);
|
||||
}
|
||||
|
||||
strLstAdd(commandParamList, STR(argList[optind - 1]));
|
||||
}
|
||||
|
||||
|
@ -634,6 +634,15 @@ testRun(void)
|
||||
TEST_ERROR(
|
||||
configParse(strLstSize(argList), strLstPtr(argList), false), ParamInvalidError, "command does not allow parameters");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
argList = strLstNew();
|
||||
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
||||
strLstAdd(argList, CFGCMD_ARCHIVE_PUSH_STR);
|
||||
strLstAdd(argList, strNew("%p"));
|
||||
TEST_ERROR(
|
||||
configParse(strLstSize(argList), strLstPtr(argList), false), ParamInvalidError,
|
||||
"invalid percent character in parameter 1");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
argList = strLstNew();
|
||||
strLstAdd(argList, strNew(TEST_BACKREST_EXE));
|
||||
|
Loading…
Reference in New Issue
Block a user