comparison src/event/ngx_event.c @ 8106:8852f39311de

Fixed segfault when switching off master process during upgrade. Binary upgrades are not supported without master process, but it is, however, possible, that nginx running with master process is asked to upgrade binary, and the configuration file as available on disk at this time includes "master_process off;". If this happens, listening sockets inherited from the previous binary will have ls[i].previous set. But the old cycle on initial process startup, including startup after binary upgrade, is destroyed by ngx_init_cycle() once configuration parsing is complete. As a result, an attempt to dereference ls[i].previous in ngx_event_process_init() accesses already freed memory. Fix is to avoid looking into ls[i].previous if the old cycle is already freed. With this change it is also no longer needed to clear ls[i].previous in worker processes, so the relevant code was removed.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 23 Nov 2022 23:48:53 +0300
parents 09463dd9c504
children 91ad1abfb285
comparison
equal deleted inserted replaced
8105:09463dd9c504 8106:8852f39311de
811 811
812 #if (NGX_HAVE_DEFERRED_ACCEPT) 812 #if (NGX_HAVE_DEFERRED_ACCEPT)
813 rev->deferred_accept = ls[i].deferred_accept; 813 rev->deferred_accept = ls[i].deferred_accept;
814 #endif 814 #endif
815 815
816 if (!(ngx_event_flags & NGX_USE_IOCP_EVENT)) { 816 if (!(ngx_event_flags & NGX_USE_IOCP_EVENT)
817 && cycle->old_cycle)
818 {
817 if (ls[i].previous) { 819 if (ls[i].previous) {
818 820
819 /* 821 /*
820 * delete the old accept events that were bound to 822 * delete the old accept events that were bound to
821 * the old cycle read events array 823 * the old cycle read events array