Skip to content

Commit 18404ea

Browse files
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
1 parent 915de70 commit 18404ea

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/test/modules/test_tidstore/test_tidstore.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ sanity_check_array(ArrayType *ta)
146146
errmsg("argument must be empty or one-dimensional array")));
147147
}
148148

149+
static void
150+
check_tidstore_available(void)
151+
{
152+
if (tidstore == NULL)
153+
elog(ERROR, "tidstore is not created");
154+
}
155+
149156
static void
150157
purge_from_verification_array(BlockNumber blkno)
151158
{
@@ -167,6 +174,7 @@ do_set_block_offsets(PG_FUNCTION_ARGS)
167174
OffsetNumber *offs;
168175
int noffs;
169176

177+
check_tidstore_available();
170178
sanity_check_array(ta);
171179

172180
noffs = ArrayGetNItems(ARR_NDIM(ta), ARR_DIMS(ta));
@@ -217,6 +225,8 @@ check_set_block_offsets(PG_FUNCTION_ARGS)
217225
int num_lookup_tids = 0;
218226
BlockNumber prevblkno = 0;
219227

228+
check_tidstore_available();
229+
220230
/* lookup each member in the verification array */
221231
for (int i = 0; i < items.num_tids; i++)
222232
if (!TidStoreIsMember(tidstore, &items.insert_tids[i]))
@@ -305,6 +315,8 @@ test_is_full(PG_FUNCTION_ARGS)
305315
{
306316
bool is_full;
307317

318+
check_tidstore_available();
319+
308320
is_full = (TidStoreMemoryUsage(tidstore) > tidstore_empty_size);
309321

310322
PG_RETURN_BOOL(is_full);
@@ -314,6 +326,8 @@ test_is_full(PG_FUNCTION_ARGS)
314326
Datum
315327
test_destroy(PG_FUNCTION_ARGS)
316328
{
329+
check_tidstore_available();
330+
317331
TidStoreDestroy(tidstore);
318332
tidstore = NULL;
319333
items.num_tids = 0;

0 commit comments

Comments
 (0)