nginx-rtmp-module
nginx-rtmp-module copied to clipboard
Workers segfault when auto_pushed to and IPv6 is used for RTMP
I'm running nginx-rtmp with the following configuration (abridged):
worker_processes 2;
rtmp_auto_push on;
rtmp {
server {
listen [::]:1935 ipv6only=off;
application stream {
live on;
allow publish 127.0.0.1;
deny publish all;
allow play all;
}
}
}
Second worker segfaults from time to time. I've looked into the issue, and believe the following is happening:
- When the second worker is created, it inherits the parents' list of listening sockets.
- In
ngx_rtmp_auto_push_init_process, thisngx_listening_tis cloned and partially replaced by the UNIX domain socket for auto_push.ls->servers, however, remains the same, containing angx_rtmp_port_tand in turn angx_rtmp_in6_addr_t, which then contains both astruct in6_addrand angx_rtmp_addr_conf_t. - When the first worker connects to the second worker via this socket,
ngx_rtmp_init_connectionis called. Asc->local_sockaddr->sa_familyisAF_UNIX,unix_socketis set and execution then falls through to theAF_INETcase, which causes thengx_rtmp_in6_addr_tto be reinterpreted as angx_rtmp_in_addr_t. (this is the bug) addr_confis now read from an incorrect offset inside the structure, which causes an invalid memory access (a null pointer dereference in my case, becausein6_addrcontains a lot of zeros) later inngx_rtmp_init_session(inaddr_conf->ctx).
Additionally, the code in ngx_rtmp_init_connection handling the port->naddrs > 1-case for AF_UNIX connections does not make any sense, because sa won't be a struct sockaddr_in. But this is unrelated to the main problem.