The calculation didn't take into account the NULL terminator. That lead
to overwriting the palloc'd buffer by one byte, if the input consists
entirely of backslashes. For example "format('%L', E'\\')".
Fixes bug #14468. Backpatch to all supported versions.
Report: https://www.postgresql.org/message-id/
20161216105001.13334.42819%40wrigleys.postgresql.org
len = strlen(rawstr);
/* We make a worst-case result area; wasting a little space is OK */
- result = palloc(len * 2 + 3);
+ result = palloc(len * 2 + 3 + 1);
newlen = quote_literal_internal(result, rawstr, len);
result[newlen] = '\0';