Thread

Commits

  1. Fix use-after-free issue in slot synchronization.

  1. Fix use of variable after pfree

    Shlok Kyal <shlok.kyal.oss@gmail.com> — 2025-09-02T07:32:23Z

    Hi,
    
    While going through the code of the slot sync worker, I found that in
    functions ReplSlotSyncWorkerMain and pg_sync_replication_slots the
    variable app_name.data is being used after it is freed.
    
    We can get logs as following:
    2025-09-02 12:26:48.520 IST [3908359] ERROR:  synchronization worker
    "" could not connect to the primary server: connection to server at
    "localhost" (127.0.0.1), port 5432 failed: Connection refused
            Is the server running on that host and accepting TCP/IP connections?
    
    I have moved the pfree(app_data.name) after its usage.
    
    This change was introduced in PG_18.
    The patch applies in the HEAD and REL_18_STABLE branches.
    
    Thanks,
    Shlok Kyal
    
  2. Re: Fix use of variable after pfree

    Amit Kapila <amit.kapila16@gmail.com> — 2025-09-02T07:42:49Z

    On Tue, Sep 2, 2025 at 1:02 PM Shlok Kyal <shlok.kyal.oss@gmail.com> wrote:
    >
    > Hi,
    >
    > While going through the code of the slot sync worker, I found that in
    > functions ReplSlotSyncWorkerMain and pg_sync_replication_slots the
    > variable app_name.data is being used after it is freed.
    >
    > We can get logs as following:
    > 2025-09-02 12:26:48.520 IST [3908359] ERROR:  synchronization worker
    > "" could not connect to the primary server: connection to server at
    > "localhost" (127.0.0.1), port 5432 failed: Connection refused
    >         Is the server running on that host and accepting TCP/IP connections?
    >
    > I have moved the pfree(app_data.name) after its usage.
    >
    > This change was introduced in PG_18.
    > The patch applies in the HEAD and REL_18_STABLE branches.
    >
    
    Thanks for the patch. It looks good to me. I'll take care of it.
    
    -- 
    With Regards,
    Amit Kapila.
    
    
    
    
  3. Re: Fix use of variable after pfree

    Daniel Gustafsson <daniel@yesql.se> — 2025-09-02T08:56:26Z

    > On 2 Sep 2025, at 09:42, Amit Kapila <amit.kapila16@gmail.com> wrote:
    > On Tue, Sep 2, 2025 at 1:02 PM Shlok Kyal <shlok.kyal.oss@gmail.com> wrote:
    
    >> While going through the code of the slot sync worker, I found that in
    >> functions ReplSlotSyncWorkerMain and pg_sync_replication_slots the
    >> variable app_name.data is being used after it is freed.
    >> 
    >> We can get logs as following:
    >> 2025-09-02 12:26:48.520 IST [3908359] ERROR:  synchronization worker
    >> "" could not connect to the primary server: connection to server at
    >> "localhost" (127.0.0.1), port 5432 failed: Connection refused
    >>        Is the server running on that host and accepting TCP/IP connections?
    >> 
    >> I have moved the pfree(app_data.name) after its usage.
    >> 
    >> This change was introduced in PG_18.
    >> The patch applies in the HEAD and REL_18_STABLE branches.
    > 
    > Thanks for the patch. It looks good to me. I'll take care of it.
    
    Agreed, this looks correct.
    
    --
    Daniel Gustafsson