Avoid possible longjmp-induced logic error in PLy_trigger_build_args.
The "pltargs" variable wasn't marked volatile, which makes it unsafe to change its value within the PG_TRY block. It looks like the worst outcome would be to fail to release a refcount on Py_None during an (improbable) error exit, which would likely go unnoticed in the field. Still, it's a bug. A one-liner fix could be to mark pltargs volatile, but on the whole it seems cleaner to arrange things so that we don't change its value within PG_TRY. Per report from Xing Guo. This has been there for quite awhile, so back-patch to all supported branches. Discussion: https://postgr.es/m/CACpMh+DLrk=fDv07MNpBT4J413fDAm+gmMXgi8cjPONE+jvzuw@mail.gmail.com
This commit is contained in:
parent
de3c5b1872
commit
fb60118bf2
@ -693,7 +693,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
|
|||||||
*pltrelid,
|
*pltrelid,
|
||||||
*plttablename,
|
*plttablename,
|
||||||
*plttableschema,
|
*plttableschema,
|
||||||
*pltargs = NULL,
|
*pltargs,
|
||||||
*pytnew,
|
*pytnew,
|
||||||
*pytold,
|
*pytold,
|
||||||
*pltdata;
|
*pltdata;
|
||||||
@ -717,6 +717,11 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
pltargs = Py_None;
|
||||||
|
}
|
||||||
|
|
||||||
PG_TRY();
|
PG_TRY();
|
||||||
{
|
{
|
||||||
@ -860,7 +865,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
|
|||||||
PyObject *pltarg;
|
PyObject *pltarg;
|
||||||
|
|
||||||
/* pltargs should have been allocated before the PG_TRY block. */
|
/* pltargs should have been allocated before the PG_TRY block. */
|
||||||
Assert(pltargs);
|
Assert(pltargs && pltargs != Py_None);
|
||||||
|
|
||||||
for (i = 0; i < tdata->tg_trigger->tgnargs; i++)
|
for (i = 0; i < tdata->tg_trigger->tgnargs; i++)
|
||||||
{
|
{
|
||||||
@ -874,8 +879,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Py_INCREF(Py_None);
|
Assert(pltargs == Py_None);
|
||||||
pltargs = Py_None;
|
|
||||||
}
|
}
|
||||||
PyDict_SetItemString(pltdata, "args", pltargs);
|
PyDict_SetItemString(pltdata, "args", pltargs);
|
||||||
Py_DECREF(pltargs);
|
Py_DECREF(pltargs);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user