1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-05 15:05:48 +02:00

Fix handling of \ in filenames.

\ was not being properly escaped when calculating the manifest checksum which prevented the manifest from loading.

Use jsonFromStr() to properly quote and escape \.

Since instances of \ in cluster filenames should be rare to nonexistent this does not seem likely to be a serious problem in the field.
This commit is contained in:
David Steele 2019-12-13 21:33:13 -05:00
parent f0ef73db70
commit 03849840b8
4 changed files with 16 additions and 9 deletions

View File

@ -14,6 +14,14 @@
<release-list>
<release date="XXXX-XX-XX" version="2.21dev" title="UNDER DEVELOPMENT">
<release-core-list>
<release-bug-list>
<release-item>
<p>Fix handling of <id>\</id> in filenames.</p>
<p><id>\</id> was not being properly escaped when calculating the manifest checksum which prevented the manifest from loading. Since instances of <id>\</id> in cluster filenames should be rare to nonexistent this does not seem likely to be a serious problem in the field.</p>
</release-item>
</release-bug-list>
<release-feature-list>
<release-item>
<p><backrest/> is now pure <proper>C</proper>.</p>

View File

@ -82,13 +82,12 @@ BUFFER_STRDEF_STATIC(INFO_CHECKSUM_SECTION_NEXT_END_BUF, "},");
} \
while (0)
BUFFER_STRDEF_STATIC(INFO_CHECKSUM_KEY_VALUE_END_BUF, "\":");
BUFFER_STRDEF_STATIC(INFO_CHECKSUM_KEY_VALUE_END_BUF, ":");
#define INFO_CHECKSUM_KEY_VALUE(checksum, key, value) \
do \
{ \
ioFilterProcessIn(checksum, QUOTED_BUF); \
ioFilterProcessIn(checksum, BUFSTR(key)); \
ioFilterProcessIn(checksum, BUFSTR(jsonFromStr(key))); \
ioFilterProcessIn(checksum, INFO_CHECKSUM_KEY_VALUE_END_BUF); \
ioFilterProcessIn(checksum, BUFSTR(value)); \
} \

View File

@ -51,9 +51,8 @@ harnessInfoChecksumCallback(void *callbackData, const String *section, const Str
else
ioFilterProcessIn(data->checksum, BUFSTRDEF(","));
ioFilterProcessIn(data->checksum, BUFSTRDEF("\""));
ioFilterProcessIn(data->checksum, BUFSTR(key));
ioFilterProcessIn(data->checksum, BUFSTRDEF("\":"));
ioFilterProcessIn(data->checksum, BUFSTR(jsonFromStr(key)));
ioFilterProcessIn(data->checksum, BUFSTRDEF(":"));
ioFilterProcessIn(data->checksum, BUFSTR(value));
}

View File

@ -1672,7 +1672,8 @@ testRun(void)
"pg_data/base/32768/33000.32767={\"checksum\":\"6e99b589e550e68e934fd235ccba59fe5b592a9e\",\"checksum-page\":true" \
",\"reference\":\"20190818-084502F\",\"size\":32768,\"timestamp\":1565282114}\n" \
"pg_data/postgresql.conf={\"master\":true,\"size\":4457,\"timestamp\":1565282114}\n" \
"pg_data/special={\"master\":true,\"mode\":\"0640\",\"size\":0,\"timestamp\":1565282120,\"user\":false}\n"
"pg_data/special-@#!$^&*()_+~`{}[]\\:;={\"master\":true,\"mode\":\"0640\",\"size\":0,\"timestamp\":1565282120" \
",\"user\":false}\n" \
#define TEST_MANIFEST_FILE_DEFAULT \
"\n" \
@ -1827,8 +1828,8 @@ testRun(void)
manifestFileFindDefault(manifest, STRDEF("bogus"), file)->name, "pg_data/PG_VERSION",
"manifestFileFindDefault() - return default");
TEST_RESULT_STR_Z(
manifestFileFindDefault(manifest, STRDEF("pg_data/special"), file)->name, "pg_data/special",
"manifestFileFindDefault() - return found");
manifestFileFind(manifest, STRDEF("pg_data/special-@#!$^&*()_+~`{}[]\\:;"))->name,
"pg_data/special-@#!$^&*()_+~`{}[]\\:;", "find special file");
TEST_ASSIGN(file, manifestFileFindDefault(manifest, STRDEF("bogus"), NULL), "manifestFileFindDefault()");
TEST_RESULT_PTR(file, NULL, " return default NULL");