On 20 May 2016 at 19:13, Hao Lee <mixtrue@gmail.com> wrote:
>
> Hi all,
>
> Today, I am do some works on adding some customized featues to PostgreSQL 9.6 beta1. But, when i do some output to
psqlusing the fuction "do_text_output_multiline" with the string just like mentioned in mail tilte, such as "this is
a\ntestfor\nnew blank.". the PostgreSQL may lead to corruption in this function, and i debugged it that found this
functioncan not dealt with the boundaries properly. The original function code as :
>
> do_text_output_multiline(TupOutputState *tstate, char *text)
> {
> Datum values[1];
> bool isnull[1] = {false};
>
> while (*text)
> {
> char *eol;
> int len;
>
> eol = strchr(text, '\n');
> if (eol)
> {
> len = eol - text;
>
> eol++;
> }
> else
> {
> len = strlen(text);
> eol += len;
> }
>
> values[0] = PointerGetDatum(cstring_to_text_with_len(text, len));
> do_tup_output(tstate, values, isnull);
> pfree(DatumGetPointer(values[0]));
> text = eol;
> }
> }
>
Thanks for reporting this. It does seem pretty broken. I guess we've
only gotten away with this due to EXPLAIN output lines always having a
\n at the end of them, but we should fix this.
Your proposed fix looks a little bit confused. You could have just
removed the eol += len; as testing if (eol) in the else will never be
true as that else is only being hit because eol is NULL.
I shuffled things around in there a bit and came up with the attached fix.
--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services