1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-10-23 21:28:56 +03:00

Reject \u0000 when reading JSON strings.

jsonReadStr() decoded a \u0000 escape and appended a null character to the string. This asserted in debug builds and created a string with an embedded null in production builds, which is cut short anywhere the string is used as a zero-terminated string.

Error on \u0000. A string cannot store a null character.
This commit is contained in:
David Steele
2026-10-12 10:27:52 +02:00
parent 2b919843ad
commit 1808295ccd
2 changed files with 8 additions and 2 deletions

View File

@@ -1047,9 +1047,14 @@ jsonReadStr(JsonRead *const this)
THROW_FMT(JsonFormatError, "unable to decode at: %s", this->json - 2);
}
// Decode char
// Decode char. A null character cannot be stored in a string.
this->json += 2;
strCatChr(result, (char)cvtZSubNToUIntBase(this->json, 0, 2, 16));
const char decode = (char)cvtZSubNToUIntBase(this->json, 0, 2, 16);
if (decode == '\0')
THROW_FMT(JsonFormatError, "unable to decode at: %s", this->json - 4);
strCatChr(result, decode);
this->json++;
break;

View File

@@ -74,6 +74,7 @@ testRun(void)
TEST_ERROR(jsonReadStr(jsonReadNew(STRDEF("\"\\u1111"))), JsonFormatError, "unable to decode at: \\u1111");
TEST_ERROR(jsonReadStr(jsonReadNew(STRDEF("\"\\u00x1"))), JsonFormatError, "unable to decode at: \\u00x1");
TEST_ERROR(jsonReadStr(jsonReadNew(STRDEF("\"\\u00a"))), JsonFormatError, "unable to decode at: \\u00a");
TEST_ERROR(jsonReadStr(jsonReadNew(STRDEF("\"\\u0000\""))), JsonFormatError, "unable to decode at: \\u0000\"");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("error on maximum depth");