Skip to content

Commit 229b480

Browse files
authored
[BABEL] Fix Invalid Read in IsTopTransactionName (#739) (#745)
SetTopTransactionName() stores the transaction name in TopTransactionContext memory. When the transaction ends, this memory is freed but the name pointer is not set to NULL, leaving a dangling pointer. A subsequent call to IsTopTransactionName() then reads freed memory via strcmp(). Introduce ResetTopTransactionName() which NULLs out name. This is called from pltsql_xact_cb to ensure the pointer is reset on every transaction end. Extension PR: babelfish-for-postgresql/babelfish_extensions#4717 Task: BABEL-5245 Authored-by: Rucha Kulkarni ruchask@amazon.com
1 parent 06078bd commit 229b480

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/backend/access/transam/xact.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6338,6 +6338,12 @@ SetTopTransactionName(const char *name)
63386338
s->name = MemoryContextStrdup(TopTransactionContext, name);
63396339
}
63406340

6341+
void
6342+
ResetTopTransactionName(void)
6343+
{
6344+
CurrentTransactionState->name = NULL;
6345+
}
6346+
63416347
/*
63426348
* IsTrasactionBlockActive
63436349
* If a transaction block is already in progress

src/include/access/xact.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ extern bool IsInParallelMode(void);
529529

530530
extern PGDLLEXPORT bool IsTopTransactionName(const char *name);
531531
extern PGDLLEXPORT void SetTopTransactionName(const char *name);
532+
extern PGDLLEXPORT void ResetTopTransactionName(void);
532533
extern PGDLLEXPORT bool IsTransactionBlockActive(void);
533534
extern PGDLLEXPORT void RollbackAndReleaseSavepoint(const char *name);
534535

0 commit comments

Comments
 (0)