diff --git a/src/bin/pg_verifybackup/parse_manifest.c b/src/bin/pg_verifybackup/parse_manifest.c index 3b13ae5b84..c7ccc78c70 100644 --- a/src/bin/pg_verifybackup/parse_manifest.c +++ b/src/bin/pg_verifybackup/parse_manifest.c @@ -147,7 +147,7 @@ json_parse_manifest(JsonManifestParseContext *context, char *buffer, /* Run the actual JSON parser. */ json_error = pg_parse_json(lex, &sem); if (json_error != JSON_SUCCESS) - json_manifest_parse_failure(context, json_errdetail(json_error, lex)); + json_manifest_parse_failure(context, "parsing failed"); if (parse.state != JM_EXPECT_EOF) json_manifest_parse_failure(context, "manifest ended unexpectedly"); diff --git a/src/bin/pg_verifybackup/t/005_bad_manifest.pl b/src/bin/pg_verifybackup/t/005_bad_manifest.pl index 9f8a100a71..4f5b8f5a49 100644 --- a/src/bin/pg_verifybackup/t/005_bad_manifest.pl +++ b/src/bin/pg_verifybackup/t/005_bad_manifest.pl @@ -16,7 +16,7 @@ my $tempdir = TestLib::tempdir; test_bad_manifest( 'input string ended unexpectedly', - qr/could not parse backup manifest: The input string ended unexpectedly/, + qr/could not parse backup manifest: parsing failed/, <semstate); @@ -478,7 +469,9 @@ parse_array(JsonLexContext *lex, JsonSemAction *sem) json_struct_action aend = sem->array_end; JsonParseErrorType result; +#ifndef FRONTEND check_stack_depth(); +#endif if (astart != NULL) (*astart) (sem->semstate); @@ -1044,15 +1037,34 @@ report_parse_error(JsonParseContext ctx, JsonLexContext *lex) /* * We don't use a default: case, so that the compiler will warn about - * unhandled enum values. But this needs to be here anyway to cover the - * possibility of an incorrect input. + * unhandled enum values. */ - json_log_and_abort("unexpected json parse state: %d", (int) ctx); + Assert(false); return JSON_SUCCESS; /* silence stupider compilers */ } + +#ifndef FRONTEND +/* + * Extract the current token from a lexing context, for error reporting. + */ +static char * +extract_token(JsonLexContext *lex) +{ + int toklen = lex->token_terminator - lex->token_start; + char *token = palloc(toklen + 1); + + memcpy(token, lex->token_start, toklen); + token[toklen] = '\0'; + return token; +} + /* * Construct a detail message for a JSON error. + * + * Note that the error message generated by this routine may not be + * palloc'd, making it unsafe for frontend code as there is no way to + * know if this can be safery pfree'd or not. */ char * json_errdetail(JsonParseErrorType error, JsonLexContext *lex) @@ -1115,20 +1127,7 @@ json_errdetail(JsonParseErrorType error, JsonLexContext *lex) * unhandled enum values. But this needs to be here anyway to cover the * possibility of an incorrect input. */ - json_log_and_abort("unexpected json parse error type: %d", (int) error); - return NULL; /* silence stupider compilers */ -} - -/* - * Extract the current token from a lexing context, for error reporting. - */ -static char * -extract_token(JsonLexContext *lex) -{ - int toklen = lex->token_terminator - lex->token_start; - char *token = palloc(toklen + 1); - - memcpy(token, lex->token_start, toklen); - token[toklen] = '\0'; - return token; + elog(ERROR, "unexpected json parse error type: %d", (int) error); + return NULL; } +#endif