aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-01-20 23:43:51 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2013-01-20 23:43:51 -0500
commit9a3ddecdd9261856b1091da0f7a86fa41430eaa2 (patch)
tree2a378e13dda52ea930cb50644d986c878df6210d
parent666569f1fde8fbf42ca00ff08c5309c348958889 (diff)
downloadpostgresql-9a3ddecdd9261856b1091da0f7a86fa41430eaa2.tar.gz
postgresql-9a3ddecdd9261856b1091da0f7a86fa41430eaa2.zip
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
-rw-r--r--src/interfaces/libpq/fe-print.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c
index 94ef40d3bcb..585e831cdb6 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);
}