Skip to content

caddyfile: reject negative import argument indices - #8316

Merged
steadytao merged 2 commits into
caddyserver:masterfrom
BenMacha:fix-import-args-negative-index
Nov 3, 2026
Merged

steadytao merged 2 commits into
caddyserver:masterfrom
BenMacha:fix-import-args-negative-index

Conversation

@BenMacha

@BenMacha BenMacha commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

{args[-1]} and {args.-1} parsed as -1 and indexed the args slice
directly, panicking with index out of range. Treat negative indices as
out of bounds, like indices past the end.

Assistance Disclosure

The bug was found during a code review done with Claude Code (Anthropic), which also drafted the fix and the test. I reviewed the change, can explain every line, and ran go test -race -short on the affected package before opening this PR.

{args[-1]} and {args.-1} parsed as -1 and indexed the args slice
directly, panicking with index out of range. Treat negative indices as
out of bounds, like indices past the end.
@caddy-cla

caddy-cla Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

✅ Contributor License Agreement

All identified contributors have signed the CLA. Thank you!

@steadytao
steadytao enabled auto-merge (squash) November 3, 2026 06:49
@steadytao steadytao added the bug 🐞 Something isn't working label Nov 3, 2026
@steadytao steadytao added this to the v2.12.0 milestone Nov 3, 2026
@steadytao
steadytao merged commit 482f867 into caddyserver:master Nov 3, 2026
27 checks passed
This was referenced Nov 3, 2026
NickCao pushed a commit to NickCao/caddy that referenced this pull request Nov 4, 2026
{args[-1]} and {args.-1} parsed as -1 and indexed the args slice
directly, panicking with index out of range. Treat negative indices as
out of bounds, like indices past the end.

(cherry picked from commit 482f867)
@francislavoie francislavoie modified the milestones: v2.12.0, v2.11.8 Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants