Fix segfault: stop storing NTLM cache item in c->data on idle upstream connections#4
Merged
matthias-lay merged 4 commits intomasterfrom May 6, 2026
Merged
Conversation
…LM cache nginx's ngx_http_upstream_handler() assumes r = c->data is ngx_http_request_t*. Storing our cache item in c->data causes segfaults when posted/ready events fire for cached upstream connections. Fix: store the cache item in c->read->data instead. Since we replace c->read->handler with our own handler, only our handler runs for idle connections and retrieves item via ev->data. Restore c->read->data = c in get_ntlm_peer before returning the connection to upstream core. Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/2e9fcf2a-dc92-4dda-831c-76cc616351af Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix segfaults by removing unsafe use of ngx_connection_t->data
Fix segfault: stop storing NTLM cache item in c->data on idle upstream connections
May 6, 2026
…otify passthrough), 5 (eviction NULL guard) Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/672b9196-95fe-4861-bee8-50b1cc5ff159 Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
…equests->max_requests Agent-Logs-Url: https://github.com/Securepoint/nginx-ntlm-module/sessions/672b9196-95fe-4861-bee8-50b1cc5ff159 Co-authored-by: matthias-lay <163420385+matthias-lay@users.noreply.github.com>
Copilot stopped work on behalf of
matthias-lay due to an error
May 6, 2026 09:48
Copilot stopped work on behalf of
matthias-lay due to an error
May 6, 2026 10:06
Copilot stopped work on behalf of
matthias-lay due to an error
May 6, 2026 10:07
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.
c->data = NULLwhen caching a connection infree_ntlm_peerntlm_requests/ntlm_timedirectives and enforcec->requests/c->start_timelimits infree_ntlm_peernotifypeer callback ininit_ntlm_peerold_pcin cache-eviction path infree_ntlm_peerc->read->data = cbeforec->data = NULLinget_ntlm_peerfor clearer orderingrequests→max_requestsfor clarityOriginal prompt
Extend existing PR #3 in Securepoint/nginx-ntlm-module to fully fix segfaults by removing unsafe use of ngx_connection_t->data.
Context
Requirements
Deliverable
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: ```
static void
ngx_http_upstream_handler(ngx_event_t *ev)
{
ngx_connection_t *c;
ngx_http_request_t *r;
ngx_http_upstream_t *u;
}
Instead, store
itemsomewhere that won’t break upstream assumptions. Common patterns:c->read->data = item;c->write->data = item;(and in your handlers, get
item = ev->dataor keepev->data = cand putitemin another field—depends on nginx struct layout/version)ngx_connection_t *(rbtree/hash) managed by the module.ngx_http_request_t *r(or NULL when idle)ngx_http_upstream_ntlm_cache_t *itemand only set
c->datato that wrapper if you also ensure upstream handler will never see it (usua...This pull request was created from Copilot chat.