Re: add some more error checks into _fileExistsInDirectory function to report "too long name" error

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Mahendra Singh Thalor <mahi6run(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Subject: Re: add some more error checks into _fileExistsInDirectory function to report "too long name" error
Date: 2025-04-11 13:08:30
Message-ID: CB93153C-17A0-421B-AE8F-63C22D0CFFED@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 11 Apr 2025, at 14:26, Mahendra Singh Thalor <mahi6run(at)gmail(dot)com> wrote:
>
> Hi,
> In another thread[1], Álvaro gave some feedback for _fileExistsInDirectory function for "too long name" error.
> Basically, in _fileExistsInDirectory function, we pass dirname and filename but we were checking only the combined length of these two names.

My interpretation of the original problem in the other thread is that the
errormessage isn't applicable for a generic function as it only mention
directory, not that checking the combination is inherently wrong.

> Here, I am attaching a patch which will check lengths of dirname and filename separately and will report errors if the name is too long.

Since we only care about the combination of directory and filename, do we
really gain much by using separate checks? A proposed filename exceeding
MAXPGPATH should be pretty rare in production I'd hope.

+ if (snprintf(buf, MAXPGPATH, "%s/%s", dir, filename) >= MAXPGPATH)
+ pg_fatal("combined name of directory:\"%s\" and file:\"%s\" is too long", filename, dir);

snprintf() will return a negative value in case of an error so if we really
want to clamp down on path generation we should probably check that as well.

--
Daniel Gustafsson

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message torikoshia 2025-04-11 13:18:06 Re: RFC: Allow EXPLAIN to Output Page Fault Information
Previous Message Mahendra Singh Thalor 2025-04-11 12:30:02 Re: merge file_exists_in_directory and _fileExistsInDirectory functions and move into common file dumputils.c