Skip to content

[mod_amqp] prevent segfault on double connection close#3054

Open
greenbea wants to merge 1 commit into
signalwire:masterfrom
greenbea:fix_amqp_segfault
Open

[mod_amqp] prevent segfault on double connection close#3054
greenbea wants to merge 1 commit into
signalwire:masterfrom
greenbea:fix_amqp_segfault

Conversation

@greenbea

@greenbea greenbea commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

When a command response publish failed, mod_amqp_command_response closed the connection and cleared conn_active. The command thread teardown then called mod_amqp_connection_close(NULL), causing a segfault.

Here's the test I've used to reproduce this.
test.zip

Also fix amqp_error_string2() calls to pass status codes without erroneous negation.

Description

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Code cleanup / refactor

Related Issues

Testing

  • Added/updated unit tests
  • Tested manually
  • Tested with live SignalWire credentials (if applicable)

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the project's style guidelines
  • I have added tests for my changes (if applicable)
  • I have updated documentation (if applicable)
  • All existing tests pass

Additional Notes

When a command response publish failed, `mod_amqp_command_response` closed
the connection and cleared conn_active. The command thread teardown then
called mod_amqp_connection_close(NULL), causing a segfault.

Also fix amqp_error_string2() calls to pass status codes without erroneous negation.
@greenbea

Copy link
Copy Markdown
Contributor Author

segfault

Core was generated by `/usr/bin/freeswitch -u www-data -g www-data -ncwait -nonat'.
Program terminated with signal SIGSEGV, Segmentation fault.
--Type <RET> for more, q to quit, c to continue without paging--
#0  0x00007f16721ab085 in mod_amqp_connection_close (connection=0x0) at mod_amqp_connection.c:43.
43              amqp_connection_state_t old_state;
[Current thread is 1 (Thread 0x7f16721456c0 (LWP 1804290))]
(gdb) bt
#0  0x00007f16721ab085 in mod_amqp_connection_close (connection=0x0) at mod_amqp_connection.c:43
#1  0x00007f16721ade10 in mod_amqp_command_thread (thread=0x5619eb370498, data=<optimized out>) at mod_amqp_command.c:501
#2  0x00007f167a0a71f5 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#3  0x00007f167a1278dc in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:62
#4  0x0000000000000000 in ?? ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant