Fix a bug in extension_file_exists()

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Fix a bug in extension_file_exists()
Date: 2026-02-09 09:21:17
Message-ID: 362EA9B3-589B-475A-A16E-F10C30426E28@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I just noticed a bug in extension_file_exists():

```
bool
extension_file_exists(const char *extensionName)
{
bool result = false;
List *locations;
DIR *dir;
struct dirent *de;

locations = get_extension_control_directories();

foreach_ptr(char, location, locations) // <== Here type char is wrong
{
dir = AllocateDir(location);
```

get_extension_control_directories() returns a list of ExtensionLocation, but the loop iterates it as if it contained char *, which is incorrect. As a result, AllocateDir() and ReadDir() are called with the wrong type.

This bug is only triggered on an error path, when PostgreSQL is deciding whether to emit a hint. For example:
```
evantest=# create function f() returns int LANGUAGE plpython3u as $$return 1$$;
ERROR: language "plpython3u" does not exist
```
No hint is printed.

With this patch applied:
```
evantest=# create function f() returns int LANGUAGE plpython3u as $$return 1$$;
ERROR: language "plpython3u" does not exist
HINT: Use CREATE EXTENSION to load the language into the database.
```
So the hint is shown as intended.

Attached is a patch fixing the iteration to use ExtensionLocation and location->loc consistently.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachment Content-Type Size
v1-0001-Fix-incorrect-iteration-type-in-extension_file_ex.patch application/octet-stream 1.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Anthonin Bonnefoy 2026-02-09 09:21:59 Re: Propagate XLogFindNextRecord error to callers
Previous Message Christoph Berg 2026-02-09 08:47:07 Re: [PATCH] Add last_executed timestamp to pg_stat_statements