Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4c6744e

Browse files
committed
PL/Python: Fix potential NULL pointer dereference
Afterd0aa965, one error path inPLy_spi_execute_fetch_result() could result in the variable "result"being dereferenced after being set to NULL. Rearrange the code a bit tofix that.Also add another SPI_freetuptable() call so that that is cleared in allerror paths.discovered by John Naylor <jcnaylor@gmail.com> via scan-buildideas and review by Tom Lane
1 parent85abb5b commit4c6744e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

‎src/pl/plpython/plpy_spi.c

Lines changed: 11 additions & 6 deletions
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
returnNULL;
367+
}
365368
Py_DECREF(result->status);
366369
result->status=PyInt_FromLong(status);
367370

@@ -411,12 +414,7 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
411414

412415
Py_DECREF(result->rows);
413416
result->rows=PyList_New(rows);
414-
if (!result->rows)
415-
{
416-
Py_DECREF(result);
417-
result=NULL;
418-
}
419-
else
417+
if (result->rows)
420418
{
421419
PLy_input_setup_tuple(&ininfo,tuptable->tupdesc,
422420
exec_ctx->curr_proc);
@@ -455,6 +453,13 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
455453

456454
MemoryContextDelete(cxt);
457455
SPI_freetuptable(tuptable);
456+
457+
/* in case PyList_New() failed above */
458+
if (!result->rows)
459+
{
460+
Py_DECREF(result);
461+
result=NULL;
462+
}
458463
}
459464

460465
return (PyObject*)result;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp