[PATCH] Fix off-by-one in -T tablespace mapping length check
Thread notes
1 note#bug
hackorum-bot#bug
@global #bug
Hi,
tablespace_list_append() in pg_basebackup and add_tablespace_mapping() in
pg_combinebackup copy the -T OLDDIR=NEWDIR argument into fixed MAXPGPATH
buffers. The length check at the top of the loop is
if (dst_ptr - dst >= MAXPGPATH)
pg_fatal("directory name too long");
so a final field of exactly MAXPGPATH bytes passes the check, fills the
buffer, and leaves no terminating NUL. In pg_basebackup, new_dir is the
last member of TablespaceListCell, so later string operations on it
(strlen, strcmp, the realpath/canonicalize step) can read past the
allocation. An OLDDIR of that length is only caught by accident, when the
following '=' is examined.
The attached patch compares against MAXPGPATH - 1 in both places and adds a
TAP test to
https://www.google.com/url?q=http://010_pg_basebackup.pl&source=gmail&ust=1795696336159000&sa=E:
--tablespace-mapping '/foo=/' . ('a' x 1023) now fails with "directory name
too long".
This is a hardening fix: it needs a 1024-byte mapping argument typed by the
user, so I would not consider it a backpatch candidate unless someone sees
a reason. It applies cleanly to current master (9ebc9a458c).
Regards,
Pranav