Skip to content

Commit 70ec67e

Browse files
authored
[BABEL] Fix Invalid Read in IsTopTransactionName (#739)
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 dba1b67 commit 70ec67e

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
@@ -6543,6 +6543,12 @@ SetTopTransactionName(const char *name)
65436543
s->name = MemoryContextStrdup(TopTransactionContext, name);
65446544
}
65456545

6546+
void
6547+
ResetTopTransactionName(void)
6548+
{
6549+
CurrentTransactionState->name = NULL;
6550+
}
6551+
65466552
/*
65476553
* IsTrasactionBlockActive
65486554
* 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
@@ -535,6 +535,7 @@ extern bool IsInParallelMode(void);
535535

536536
extern PGDLLEXPORT bool IsTopTransactionName(const char *name);
537537
extern PGDLLEXPORT void SetTopTransactionName(const char *name);
538+
extern PGDLLEXPORT void ResetTopTransactionName(void);
538539
extern PGDLLEXPORT bool IsTransactionBlockActive(void);
539540
extern PGDLLEXPORT void RollbackAndReleaseSavepoint(const char *name);
540541

0 commit comments

Comments
 (0)