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

Commit f73b2bb

Browse files
committed
Fix poorly thought-through code from commit 5c3c3cd.
It's not entirely clear to me whether PyString_AsString can return null (looks like the answer might vary between Python 2 and 3). But in any case, this code's attempt to cope with the possibility was quite broken, because pstrdup() neither allows a null argument nor ever returns a null. Moreover, the code below this point assumes that "message" is a palloc'd string, which would not be the case for a dgettext result. Fix both problems by doing the pstrdup step separately.
1 parent 074050f commit f73b2bb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/pl/plpython/plpy_plpymodule.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,12 @@ PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)
424424
else
425425
so = PyObject_Str(args);
426426

427-
if (so == NULL || ((message = pstrdup(PyString_AsString(so))) == NULL))
427+
if (so == NULL || ((message = PyString_AsString(so)) == NULL))
428428
{
429429
level = ERROR;
430430
message = dgettext(TEXTDOMAIN, "could not parse error message in plpy.elog");
431431
}
432+
message = pstrdup(message);
432433

433434
Py_XDECREF(so);
434435

@@ -444,7 +445,8 @@ PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)
444445
if (PyTuple_Size(args) != 0)
445446
PLy_elog(ERROR, "the message is already specified");
446447

447-
pfree(message);
448+
if (message)
449+
pfree(message);
448450
message = object_to_string(value);
449451
}
450452
else if (strcmp(keyword, "detail") == 0)

0 commit comments

Comments
 (0)