Bug and memory leaks with access to file links with long names (Windows, MSVS)

From: Vladlen Popolitov <v(dot)popolitov(at)postgrespro(dot)ru>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Bug and memory leaks with access to file links with long names (Windows, MSVS)
Date: 2024-12-27 12:44:21
Message-ID: ac3f262fdc3613acfb88176972938fd1@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi!

PostgreSQL build under Windows with MS Visual Studio has functions to
work with
links (unlike msys2 that has own functions). If a database has link
pointing
to location longer 130 chars, function pgreadlink fails to recognise
this
link and cancels query.
The reason of the error - small buffer for link name - MAX_PATH
symbols, though this
buffer must have the place for at least 2 MAX_PATH : substitution and
print names
of the link.

How to reproduce:

If build directory has length ~100 chars or longer,
pg_rewind/004_pg_xlog_symlink
test will fail (Windows, MSVS build)

Steps to reproduce:

call "C:\Program Files\Microsoft Visual
Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
SET LC_MESSAGES=C

SET
BUILDDIR=c:\postgresql-builds\length_30\length_40\length_50\length_60\length_70\length_80\length_90\length100\
meson setup %BUILDDIR% --prefix=c:\postgresql-builds\install
c:
cd %BUILDDIR%
meson compile -C %BUILDDIR%
meson install -C %BUILDDIR%
meson test -C %BUILDDIR%

Memory leak:
In case of error the function in the code branch reporting the error
does not return
Windows file handle and Windows heap allocation for error message text.

Solution:
Proposed patch fixes link information buffer size changing it to the
documented value
MAXIMUM_REPARSE_DATA_BUFFER_SIZE,
and fixes memory leaks - the message buffer copied to a buffer on stack
with maximal message size 64Kb.

--
Best regards,

Vladlen Popolitov.

Attachment Content-Type Size
v1-0001-Fix-bug-with-access-to-file-links-with-long-name-.patch text/x-diff 2.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2024-12-27 12:46:49 Re: Test to dump and restore objects left behind by regression
Previous Message Zhijie Hou (Fujitsu) 2024-12-27 12:12:11 RE: Connection limits/permissions, slotsync workers, etc