← 输入框|github.com|刷新
Skip to content

fix(stats): guard num_open decrement against underflow - #648

Merged
rofl0r merged 1 commit into
tinyproxy:masterfrom
code1a2024:fix/stats-underflow-guard
Nov 18, 2026
Merged

rofl0r merged 1 commit into
tinyproxy:masterfrom
code1a2024:fix/stats-underflow-guard

Conversation

@code1a2024

Copy link
Copy Markdown
Contributor

STAT_CLOSE unconditionally decremented num_open (unsigned long),
but error paths like STAT_BADCONN can trigger conn_destroy_contents
→ STAT_CLOSE without a prior conn_init_contents → STAT_OPEN. This
causes num_open to wrap to ULONG_MAX, permanently skewing the
"Number of open connections" display on the stats page.

Fix: only decrement num_open when it is greater than zero, matching
the guard the caller already has in conn_destroy_contents.

Changes: 1 file, +2/-1 (stats.c)

@rofl0r

rofl0r commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

the docs change with your personal audit is unwanted; once you removed it i will review the PR.

STAT_CLOSE unconditionally decremented num_open (unsigned long),
but STAT_BADCONN and other error paths can trigger conn_destroy_contents
-> STAT_CLOSE without a prior conn_init_contents -> STAT_OPEN.
This caused num_open to wrap to ULONG_MAX, skewing all statistics.

Add a guard to only decrement when num_open > 0.
@code1a2024
code1a2024 force-pushed the fix/stats-underflow-guard branch from 0b662c2 to 73f362a Compare November 18, 2026 02:53
@code1a2024

Copy link
Copy Markdown
Contributor Author

the docs change with your personal audit is unwanted; once you removed it i will review the PR.

I'm so sorry. Now the commit is updated.

@rofl0r
rofl0r merged commit e8f2f99 into tinyproxy:master Nov 18, 2026
4 checks passed
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