Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 46c9f5d

Browse files
committed
psql: Fix invalid memory access
Due to an apparent thinko, when printing a table in expanded mode (\x), space would be allocated for 1 slot plus 1 byte per line, instead of 1 slot per line plus 1 slot for the NULL terminator. When the line count is small, reading or writing the terminator would therefore access memory beyond what was allocated.
1 parent 0ba7ff5 commit 46c9f5d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/bin/psql/print.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,8 @@ print_aligned_vertical(const printTableContent *cont, FILE *fout)
11771177
* We now have all the information we need to setup the formatting
11781178
* structures
11791179
*/
1180-
dlineptr = pg_local_malloc((sizeof(*dlineptr) + 1) * dheight);
1181-
hlineptr = pg_local_malloc((sizeof(*hlineptr) + 1) * hheight);
1180+
dlineptr = pg_local_malloc((sizeof(*dlineptr)) * (dheight + 1));
1181+
hlineptr = pg_local_malloc((sizeof(*hlineptr)) * (hheight + 1));
11821182

11831183
dlineptr->ptr = pg_local_malloc(dformatsize);
11841184
hlineptr->ptr = pg_local_malloc(hformatsize);

0 commit comments

Comments
 (0)