Re: BUG #19092: scram_free() will free on address which was not malloc()-ed in pg_scram_mech

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: 13952878799(at)163(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19092: scram_free() will free on address which was not malloc()-ed in pg_scram_mech
Date: 2025-10-21 13:14:08
Message-ID: 64F1394B-E765-4291-91CF-E6CFE019D195@yesql.se
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> On 21 Oct 2025, at 09:43, PG Bug reporting form <noreply(at)postgresql(dot)org> wrote:

> The issue is about the only implementation of pg_fe_sasl_mech interface:
> pg_scram_mech. In the init func of pg_scram_mech, the variable
> state->password is assigned by variable prep_password, which is prepared in
> function pg_saslprep(). However, pg_saslprep() will use palloc/pfree or
> malloc/free determined by FRONTEND marco。If we are in backend env,the
> prep_password will be palloc-ed in CurrentMemoryContext. The problem is
> state->password will be released by free() in the free func of
> pg_scram_mech: scram_free, and will cause 'free on address which was not
> malloc()-ed' error.

Mixing frontend and backend code like that seems to register somewhere on the
"break it and you get to keep both pieces" scale.

> This issue occurred when I was attempting to make a connection to Backend
> via libpq interfaces in Backend itself.

You tried to open a new database connection from a backend by embedding a libpq
client into the backend? Which problem are you trying to solve, maybe there is
an easier way?

--
Daniel Gustafsson

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Amit Langote 2025-10-21 13:49:22 Re: Segfault in RI UPDATE CASCADE on partitioned tables with LIKE+ATTACH child (attnum drift)
Previous Message Yuval Roth 2025-10-21 12:21:08 Version 18.0 of postgres image in dockerhub - container crashes when starting up