Skip to content

fix crash in consul_health when an entry has no Checks array - #331

Merged
gfrankliu merged 1 commit into
masterfrom
fix-consul-health-missing-checks
Oct 16, 2026
Merged

gfrankliu merged 1 commit into
masterfrom
fix-consul-health-missing-checks

Conversation

@gfrankliu

Copy link
Copy Markdown
Collaborator

ngx_http_upsync_consul_health_parse_json() reads checks->child without checking that cJSON_GetObjectItem(server_next, "Checks") returned non-NULL. A /v1/health/service/<name> entry without a Checks array crashes the worker (SIGSEGV). This has been there since consul_health was added in #183.

The fix skips only the health check loop when Checks is missing, so the server is kept and its weight=/max_fails=/fail_timeout=/down/backup tags are still applied.

Tested with an AddressSanitizer build against nginx 1.26.3 and a mock Consul health endpoint returning three entries (all checks passing; one check critical; no Checks but a weight=5 tag):

  • before: SEGV ... ngx_http_upsync_module.c:1698 in ngx_http_upsync_consul_health_parse_json
  • after:
server 10.0.0.3:9003 weight=5 max_fails=2 fail_timeout=10s;
server 10.0.0.22:9002 weight=1 max_fails=2 fail_timeout=10s down;
server 10.0.0.1:9001 weight=3 max_fails=2 fail_timeout=10s;

ngx_http_upsync_consul_health_parse_json() dereferenced the result of
cJSON_GetObjectItem(server_next, "Checks") without a NULL check, so a
health entry without a "Checks" array crashed the worker. Skip the
health check loop in that case, keeping the server and still applying
its tags.
@gfrankliu
gfrankliu merged commit e285f11 into master Oct 16, 2026
2 of 4 checks passed
@xiaokai-wang
xiaokai-wang deleted the fix-consul-health-missing-checks branch October 19, 2026 02:06
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.

2 participants