Skip to content

Commit

Permalink
[BABEL-3238] Protect get_tsql_error_details() from potential infinite…
Browse files Browse the repository at this point in the history
… loop (babelfish-for-postgresql#1397) (babelfish-for-postgresql#1413)

This code change does not resolve the root cause but it protects the
crash in elog() from happening. The code change allows us to exit
get_tsql_error_details() successfully and hopefully hit the original
issues in a more related code path instead of hitting it in elog()
which is completely unrelated to the real problem.

Signed-off-by: Kristian Lejao <[email protected]>
  • Loading branch information
lejaokri authored Apr 10, 2023
1 parent 08a8b8a commit 33f56ce
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions contrib/babelfishpg_tds/src/backend/tds/err_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ get_tsql_error_details(ErrorData *edata,

TDSInstrumentation(INSTR_TDS_UNMAPPED_ERROR);

elog(LOG, "Unmapped error found. Code: %d, Message: %s, File: %s, Line: %d, Context: %s",
edata->sqlerrcode, edata->message, edata->filename, edata->lineno, error_context);
/* Possible infinite loop of errors. Do not touch it further. */
if (!error_stack_full())
elog(LOG, "Unmapped error found. Code: %d, Message: %s, File: %s, Line: %d, Context: %s",
edata->sqlerrcode, edata->message, edata->filename, edata->lineno, error_context);

return false;
}
Expand Down Expand Up @@ -263,8 +265,10 @@ get_tsql_error_details(ErrorData *edata,
{
TDSInstrumentation(INSTR_TDS_UNMAPPED_ERROR);

elog(LOG, "Unmapped error found. Code: %d, Message: %s, File: %s, Line: %d, Context: %s",
edata->sqlerrcode, edata->message, edata->filename, edata->lineno, error_context);
/* Possible infinite loop of errors. Do not touch it further. */
if (!error_stack_full())
elog(LOG, "Unmapped error found. Code: %d, Message: %s, File: %s, Line: %d, Context: %s",
edata->sqlerrcode, edata->message, edata->filename, edata->lineno, error_context);

*tsql_error_code = ERRCODE_PLTSQL_ERROR_NOT_MAPPED;
*tsql_error_severity = 16;
Expand Down

0 comments on commit 33f56ce

Please sign in to comment.