Hi,

In our testing framework, backed by pg_regress, there exists the ability to use 
special strings
that can be replaced by environment based ones. Such an example is 
'@testtablespace@'. The
function used for this replacement is replace_string which inline replaces 
these occurrences in
original line. It is documented that the original line buffer should be large 
enough to accommodate.

However, it is rather possible and easy for subtle errors to occur, especially 
if there are multiple
occurrences to be replaced in long enough lines. Please find two distinct 
versions of a possible
solution. One, which is preferred, is using StringInfo though it requires for 
stringinfo.h to be included
in pg_regress.c. The other patch is more basic and avoids including 
stringinfo.h. As a reminder
stringinfo became available in the frontend in commit (26aaf97b683d)

Because the original replace_string() is exposed to other users, it is 
currently left intact.
Also if required, an error can be raised in the original function, in cases 
that the string is not
long enough to accommodate the replacements.

Worthwhile to mention that currently there are no such issues present in the 
test suits. It should
not hurt to do a bit better though.

//Asim and Georgios

Attachment: 0001-Use-stringInfo-instead-of-char-in-replace_string.patch
Description: Binary data

Attachment: 0001-Heap-allocated-string-version-of-replace_string.patch
Description: Binary data

Reply via email to