bugfix: prevent NULL dereference in SSL cache by ensuring old_cycle i…#2485
Merged
zhuizhuhaomeng merged 2 commits intoopenresty:masterfrom Mar 17, 2026
Merged
bugfix: prevent NULL dereference in SSL cache by ensuring old_cycle i…#2485zhuizhuhaomeng merged 2 commits intoopenresty:masterfrom
zhuizhuhaomeng merged 2 commits intoopenresty:masterfrom
Conversation
Contributor
Author
|
I don't know how to write a test for this, as this issue seems to occur only in the context of Resty. cc @zhuizhuhaomeng |
There was a problem hiding this comment.
Pull request overview
Fixes a startup crash in init_worker_by_lua* on newer nginx/OpenResty builds by ensuring the temporary “fake” cycle used during config merging has a non-NULL old_cycle, preventing a NULL dereference in nginx’s SSL cache path.
Changes:
- Ensure
fake_cycle->old_cycleis set whenNULLto avoidold_cycle->conf_ctxdereference duringmerge_loc_conf/ngx_ssl_trusted_certificate.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
src/ngx_http_lua_initworkerby.c
Outdated
Comment on lines
+124
to
+128
| * conf_ctx, so cert lookups will still find previously loaded entries. | ||
| */ | ||
| if (fake_cycle->old_cycle == NULL) { | ||
| fake_cycle->old_cycle = cycle; | ||
| } |
zhuizhuhaomeng
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…s set
I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.
If you use Resty in this way in the new 1.29.2 OpenResty
it will crash with follow backtrace
Reason
ngx_ssl_trusted_certificatein 1.27.1 directly calledSSL_CTX_load_verify_locations, with no SSL cache layer. Thengx_ssl_cache_fetch/ngx_openssl_cache_moduleis new in nginx 1.27.2. nginx/nginx#140Call chain that triggers the crash:
Call chain that triggers the crash:
ngx_init_cycle()completes → setscycle->old_cycle = NULL(ngx_cycle.c:785)ngx_single_process_cycle→ngx_http_lua_init_workerngx_http_lua_init_workercreates afake_cycleviangx_memcpy(fake_cycle, cycle, ...)--- sofake_cycle->old_cycle = NULLmerge_loc_confwith aconfpointing to thefake_cyclengx_http_lua_set_ssl→ngx_ssl_trusted_certificate(nginx 1.29.2 now usesngx_ssl_cache_fetch)ngx_ssl_cache_fetchcalls the macrongx_ssl_cache_get_old_conf(cf->cycle):cycle->old_cycleis NULL →NULL->conf_ctx→ SIGSEGV