public inbox for [email protected]  
help / color / mirror / Atom feed
From: Heikki Linnakangas <[email protected]>
To: Chao Li <[email protected]>
To: Postgres hackers <[email protected]>
Subject: Re: Fix a bug in extension_file_exists()
Date: Mon, 9 Feb 2026 12:02:10 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

On 09/02/2026 11:21, Chao Li wrote:
> 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.

Yep, good catch. This went wrong in commit f3c9e341cd, which changed the 
type of objects in the list from "char *" to "ExtensionLocation *". So 
this is master only, stable branches are not affected.

I will push the fix shortly, thanks!

- Heikki







view thread (5+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Fix a bug in extension_file_exists()
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox