Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5eac8ce

Browse files
committed
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
1 parent 91cbb4b commit 5eac8ce

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/pl/plpython/plpy_exec.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
689689
*pltrelid,
690690
*plttablename,
691691
*plttableschema,
692-
*pltargs = NULL,
692+
*pltargs,
693693
*pytnew,
694694
*pytold,
695695
*pltdata;
@@ -713,6 +713,11 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
713713
return NULL;
714714
}
715715
}
716+
else
717+
{
718+
Py_INCREF(Py_None);
719+
pltargs = Py_None;
720+
}
716721

717722
PG_TRY();
718723
{
@@ -856,7 +861,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
856861
PyObject *pltarg;
857862

858863
/* pltargs should have been allocated before the PG_TRY block. */
859-
Assert(pltargs);
864+
Assert(pltargs && pltargs != Py_None);
860865

861866
for (i = 0; i < tdata->tg_trigger->tgnargs; i++)
862867
{
@@ -870,8 +875,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
870875
}
871876
else
872877
{
873-
Py_INCREF(Py_None);
874-
pltargs = Py_None;
878+
Assert(pltargs == Py_None);
875879
}
876880
PyDict_SetItemString(pltdata, "args", pltargs);
877881
Py_DECREF(pltargs);

0 commit comments

Comments
 (0)