From: Tom Lane Date: Mon, 21 Jan 2013 04:43:46 +0000 (-0500) Subject: Fix one-byte buffer overrun in PQprintTuples(). X-Git-Tag: REL9_3_BETA1~466 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8f0d8f481e86514bb35538827df7e1e35baee368;p=thirdparty%2Fpostgresql.git Fix one-byte buffer overrun in PQprintTuples(). This bug goes back to the original Postgres95 sources. Its significance to modern PG versions is marginal, since we have not used PQprintTuples() internally in a very long time, and it doesn't seem to have ever been documented either. Still, it *is* exposed to client apps, so somebody out there might possibly be using it. Xi Wang --- diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c index 076e1ccfc5b..5c86f037d71 100644 --- a/src/interfaces/libpq/fe-print.c +++ b/src/interfaces/libpq/fe-print.c @@ -681,7 +681,6 @@ PQprintTuples(const PGresult *res, int i, j; char formatString[80]; - char *tborder = NULL; nFields = PQnfields(res); @@ -700,15 +699,15 @@ PQprintTuples(const PGresult *res, int width; width = nFields * 14; - tborder = malloc(width + 1); + tborder = (char *) malloc(width + 1); if (!tborder) { fprintf(stderr, libpq_gettext("out of memory\n")); abort(); } - for (i = 0; i <= width; i++) + for (i = 0; i < width; i++) tborder[i] = '-'; - tborder[i] = '\0'; + tborder[width] = '\0'; fprintf(fout, "%s\n", tborder); }