From: Marko Kreen Date: Mon, 28 Sep 2009 09:47:26 +0000 (+0000) Subject: console: fix string format in datarow packet X-Git-Tag: pgbouncer_1_3_2~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cfa9e85a09533139183ad49805e63c4185060d32;p=pgbouncer console: fix string format in datarow packet pgbouncer used to store strings with final '\0', which should not be there. It was not noticed thus far as any C clients did not saw anything wrong. Takeover code depends on them being zero-terminated, use a hack to make them so. --- diff --git a/src/pktbuf.c b/src/pktbuf.c index 4135af4..16167d8 100644 --- a/src/pktbuf.c +++ b/src/pktbuf.c @@ -396,8 +396,8 @@ void pktbuf_write_DataRow(PktBuf *buf, const char *tupdesc, ...) if (val) { len = strlen(val); - pktbuf_put_uint32(buf, len + 1); - pktbuf_put_string(buf, val); + pktbuf_put_uint32(buf, len); + pktbuf_put_bytes(buf, val, len); } else { /* NULL */ pktbuf_put_uint32(buf, -1); diff --git a/src/proto.c b/src/proto.c index cdfbb56..8dcb86f 100644 --- a/src/proto.c +++ b/src/proto.c @@ -349,6 +349,13 @@ int scan_text_result(MBuf *pkt, const char *tupdesc, ...) val = NULL; else val = (char *)mbuf_get_bytes(pkt, len); + + /* hack to zero-terminate the result */ + if (val) { + val--; + memmove(val, val + 1, len); + val[len] = 0; + } } else /* tuple was shorter than requested */ val = NULL;