mirror of
https://github.com/postgres/postgres.git
synced 2025-08-30 06:01:21 +03:00
Fix segmentation fault in test_tidstore.
The do_set_block_offsets() and other functions accessing the tidstore did not check if the tidstore was NULL. This led to a segmentation fault when these functions are called without calling the test_create(). This commit adds NULL checks in relevant functions of test_tidstore to raise an error instead if the tidstore is not initialized. Bug: #18483 Reported-by: Alexander Kozhemyakin Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/18483-30bfff42de238000%40postgresql.org
This commit is contained in:
@@ -146,6 +146,13 @@ sanity_check_array(ArrayType *ta)
|
|||||||
errmsg("argument must be empty or one-dimensional array")));
|
errmsg("argument must be empty or one-dimensional array")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
check_tidstore_available(void)
|
||||||
|
{
|
||||||
|
if (tidstore == NULL)
|
||||||
|
elog(ERROR, "tidstore is not created");
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
purge_from_verification_array(BlockNumber blkno)
|
purge_from_verification_array(BlockNumber blkno)
|
||||||
{
|
{
|
||||||
@@ -167,6 +174,7 @@ do_set_block_offsets(PG_FUNCTION_ARGS)
|
|||||||
OffsetNumber *offs;
|
OffsetNumber *offs;
|
||||||
int noffs;
|
int noffs;
|
||||||
|
|
||||||
|
check_tidstore_available();
|
||||||
sanity_check_array(ta);
|
sanity_check_array(ta);
|
||||||
|
|
||||||
noffs = ArrayGetNItems(ARR_NDIM(ta), ARR_DIMS(ta));
|
noffs = ArrayGetNItems(ARR_NDIM(ta), ARR_DIMS(ta));
|
||||||
@@ -217,6 +225,8 @@ check_set_block_offsets(PG_FUNCTION_ARGS)
|
|||||||
int num_lookup_tids = 0;
|
int num_lookup_tids = 0;
|
||||||
BlockNumber prevblkno = 0;
|
BlockNumber prevblkno = 0;
|
||||||
|
|
||||||
|
check_tidstore_available();
|
||||||
|
|
||||||
/* lookup each member in the verification array */
|
/* lookup each member in the verification array */
|
||||||
for (int i = 0; i < items.num_tids; i++)
|
for (int i = 0; i < items.num_tids; i++)
|
||||||
if (!TidStoreIsMember(tidstore, &items.insert_tids[i]))
|
if (!TidStoreIsMember(tidstore, &items.insert_tids[i]))
|
||||||
@@ -305,6 +315,8 @@ test_is_full(PG_FUNCTION_ARGS)
|
|||||||
{
|
{
|
||||||
bool is_full;
|
bool is_full;
|
||||||
|
|
||||||
|
check_tidstore_available();
|
||||||
|
|
||||||
is_full = (TidStoreMemoryUsage(tidstore) > tidstore_empty_size);
|
is_full = (TidStoreMemoryUsage(tidstore) > tidstore_empty_size);
|
||||||
|
|
||||||
PG_RETURN_BOOL(is_full);
|
PG_RETURN_BOOL(is_full);
|
||||||
@@ -314,6 +326,8 @@ test_is_full(PG_FUNCTION_ARGS)
|
|||||||
Datum
|
Datum
|
||||||
test_destroy(PG_FUNCTION_ARGS)
|
test_destroy(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
|
check_tidstore_available();
|
||||||
|
|
||||||
TidStoreDestroy(tidstore);
|
TidStoreDestroy(tidstore);
|
||||||
tidstore = NULL;
|
tidstore = NULL;
|
||||||
items.num_tids = 0;
|
items.num_tids = 0;
|
||||||
|
Reference in New Issue
Block a user