| From: | Raja Sai pranav <rajasaipranav0(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | [PATCH] Fix off-by-one in -T tablespace mapping length check |
| Date: | 2026-11-25 12:32:16 |
| Message-ID: | nh-b01668d2-38f8-49fb-801e-612ed4fbf891@google.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Fix-off-by-one-in-T-tablespace-mapping-length-check.patch | text/x-patch | 2.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Anthony Sotolongo | 2026-11-25 12:47:34 | Re: passwordcheck: Make the user name check case-insensitive |
| Previous Message | Daniel Gustafsson | 2026-11-25 12:30:07 | Re: Add CHECK_FOR_INTERRUPTS() to XPath result serialisation |