]> granicus.if.org Git - pgbouncer/commitdiff
console: fix string format in datarow packet
authorMarko Kreen <markokr@gmail.com>
Mon, 28 Sep 2009 09:47:26 +0000 (09:47 +0000)
committerMarko Kreen <markokr@gmail.com>
Mon, 28 Sep 2009 09:47:26 +0000 (09:47 +0000)
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.

src/pktbuf.c
src/proto.c

index 4135af4f5a9c2dbdeef5358c9cd8488b16eff0ce..16167d8bd96db342516ebf5b3acb7e08a011c3c9 100644 (file)
@@ -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);
index cdfbb56bfdb63adaacc38bd8519a4e101593a600..8dcb86f350d81cd05ef0fc9b706a6f7e0f2fb784 100644 (file)
@@ -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;