Commit 8f0d8f48 authored by Tom Lane's avatar Tom Lane

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
parent 535e69a4
...@@ -681,7 +681,6 @@ PQprintTuples(const PGresult *res, ...@@ -681,7 +681,6 @@ PQprintTuples(const PGresult *res,
int i, int i,
j; j;
char formatString[80]; char formatString[80];
char *tborder = NULL; char *tborder = NULL;
nFields = PQnfields(res); nFields = PQnfields(res);
...@@ -700,15 +699,15 @@ PQprintTuples(const PGresult *res, ...@@ -700,15 +699,15 @@ PQprintTuples(const PGresult *res,
int width; int width;
width = nFields * 14; width = nFields * 14;
tborder = malloc(width + 1); tborder = (char *) malloc(width + 1);
if (!tborder) if (!tborder)
{ {
fprintf(stderr, libpq_gettext("out of memory\n")); fprintf(stderr, libpq_gettext("out of memory\n"));
abort(); abort();
} }
for (i = 0; i <= width; i++) for (i = 0; i < width; i++)
tborder[i] = '-'; tborder[i] = '-';
tborder[i] = '\0'; tborder[width] = '\0';
fprintf(fout, "%s\n", tborder); fprintf(fout, "%s\n", tborder);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment