| Lists: | pgsql-hackers |
|---|
| From: | Florin Irion <irionr(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Cc: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
| Subject: | UBSAN crash in EventTriggerCollectAlterTSConfig (memcpy with NULL src) |
| Date: | 2026-03-03 17:33:40 |
| Message-ID: | c6fff161-9aee-4290-9ada-71e21e4d84de@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
Hi,
While working on the pg_get_domain_ddl() patch [1], I installed an
event trigger on ddl_command_end in test_setup.sql to automatically
round-trip DDL. This triggered a UBSAN crash on CI [2] that turns out
to be a pre-existing bug since b488c580aef(?).
The DROP MAPPING code path in tsearchcmds.c unconditionally calls:
```
EventTriggerCollectAlterTSConfig(stmt, cfgId, NULL, 0);
```
Inside EventTriggerCollectAlterTSConfig(), this reaches:
```
command->d.atscfg.dictIds = palloc_array(Oid, ndicts); /* ndicts=0 */
memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
^^^^^^^ NULL
```
Under -fsanitize=undefined this triggers SIGABRT and crashes the server.
The bug has been latent for 11 years because without an active event
trigger, currentEventTriggerState is NULL and the function returns early
at the top, never reaching the memcpy. The standard regression suite
never had an event trigger installed during the tsdicts test — until now.
Reproducer (crashes only under UBSAN) and patch attached:
This affects all branches back to 9.5 where b488c580aef landed.
[1] https://www.postgresql.org/message-id/CAPgqM1V4LW2qiDLPsusb7s0kYbSDJjH5Tt%2B-ZzVmPU7xV0TJNQ%40mail.gmail.com
[2] https://cirrus-ci.com/task/6170470552174592
--
Cheers,
Florin
EDB -- www.enterprisedb.com
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Add-regression-test-for-EventTriggerCollectAlterT.patch | text/plain | 3.2 KB |
| v1-0002-Fix-UBSAN-crash-in-EventTriggerCollectAlterTSConf.patch | text/plain | 1.3 KB |
| From: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
|---|---|
| To: | Florin Irion <irionr(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: UBSAN crash in EventTriggerCollectAlterTSConfig (memcpy with NULL src) |
| Date: | 2026-03-03 19:48:45 |
| Message-ID: | 202603031947.a5rjz7rgasas@alvherre.pgsql |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
On 2026-Mar-03, Florin Irion wrote:
> While working on the pg_get_domain_ddl() patch [1], I installed an
> event trigger on ddl_command_end in test_setup.sql to automatically
> round-trip DDL. This triggered a UBSAN crash on CI [2] that turns out
> to be a pre-existing bug since b488c580aef(?).
Cool, yeah, this is broken. I propose to add the corresponding test in
src/test/modules/test_ddl_deparse though -- that way we don't need
another event trigger. So how about like this?
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"No es bueno caminar con un hombre muerto"
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Don-t-malloc-0-in-EventTriggerCollectAlterTSConfi.patch | text/x-diff | 3.5 KB |
| From: | Florin Irion <irionr(at)gmail(dot)com> |
|---|---|
| To: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: UBSAN crash in EventTriggerCollectAlterTSConfig (memcpy with NULL src) |
| Date: | 2026-03-03 21:04:45 |
| Message-ID: | e2f2677b-726e-4321-9ca1-c54ea7cf6973@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
On 03/03/26 20:48, Álvaro Herrera wrote:
> Cool, yeah, this is broken. I propose to add the corresponding test in
> src/test/modules/test_ddl_deparse though -- that way we don't need
> another event trigger. So how about like this?
LGTM, I had to look up the CREATE TEXT SEARCH CONFIGURATION
first time I saw it.
Cheers,
Florin
--
EDB -- www.enterprisedb.com
| From: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
|---|---|
| To: | Florin Irion <irionr(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: UBSAN crash in EventTriggerCollectAlterTSConfig (memcpy with NULL src) |
| Date: | 2026-03-04 14:10:07 |
| Message-ID: | 202603041409.3v3sijzyr43k@alvherre.pgsql |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
On 2026-Mar-03, Florin Irion wrote:
> On 03/03/26 20:48, Álvaro Herrera wrote:
>
> > Cool, yeah, this is broken. I propose to add the corresponding test in
> > src/test/modules/test_ddl_deparse though -- that way we don't need
> > another event trigger. So how about like this?
>
> LGTM, I had to look up the CREATE TEXT SEARCH CONFIGURATION
> first time I saw it.
Okay, thanks, pushed to all branches.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"But static content is just dynamic content that isn't moving!"
http://smylers.hates-software.com/2007/08/15/fe244d0c.html
| From: | Florin Irion <irionr(at)gmail(dot)com> |
|---|---|
| To: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: UBSAN crash in EventTriggerCollectAlterTSConfig (memcpy with NULL src) |
| Date: | 2026-03-04 14:16:42 |
| Message-ID: | CA+HEvJB5rcUzi+DBf7+ckb=rYoyTEjX0MM3FxKPUErmJUv+sEQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Lists: | pgsql-hackers |
Thank you!
Il giorno mer 4 mar 2026 alle ore 15:10 Álvaro Herrera <alvherre(at)kurilemu(dot)de>
ha scritto:
> On 2026-Mar-03, Florin Irion wrote:
>
> > On 03/03/26 20:48, Álvaro Herrera wrote:
> >
> > > Cool, yeah, this is broken. I propose to add the corresponding test in
> > > src/test/modules/test_ddl_deparse though -- that way we don't need
> > > another event trigger. So how about like this?
> >
> > LGTM, I had to look up the CREATE TEXT SEARCH CONFIGURATION
> > first time I saw it.
>
> Okay, thanks, pushed to all branches.
>
> --
> Álvaro Herrera PostgreSQL Developer —
> https://www.EnterpriseDB.com/
> "But static content is just dynamic content that isn't moving!"
> http://smylers.hates-software.com/2007/08/15/fe244d0c.html
>
--
* Florin Irion *
* https://www.enterprisedb.com <https://www.enterprisedb.com/>*