Skip to content

Commit e42e2f3

Browse files
committed
PL/Python: Fix potential NULL pointer dereference
After d0aa965, one error path in PLy_spi_execute_fetch_result() could result in the variable "result" being dereferenced after being set to NULL. To fix that, just clear the resources right there and return early. Also add another SPI_freetuptable() call so that that is cleared in all error paths. discovered by John Naylor <jcnaylor@gmail.com> via scan-build
1 parent 7b88d63 commit e42e2f3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/pl/plpython/plpy_spi.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,10 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
361361

362362
result = (PLyResultObject *) PLy_result_new();
363363
if (!result)
364+
{
365+
SPI_freetuptable(tuptable);
364366
return NULL;
367+
}
365368
Py_DECREF(result->status);
366369
result->status = PyInt_FromLong(status);
367370

@@ -414,7 +417,9 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
414417
if (!result->rows)
415418
{
416419
Py_DECREF(result);
417-
result = NULL;
420+
MemoryContextDelete(cxt);
421+
SPI_freetuptable(tuptable);
422+
return NULL;
418423
}
419424
else
420425
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy