Skip to content

fix: move result counter from module global to instance variable#2991

Open
ashvinctrl wants to merge 1 commit into
sherlock-project:masterfrom
ashvinctrl:fix/globvar-instance-variable
Open

fix: move result counter from module global to instance variable#2991
ashvinctrl wants to merge 1 commit into
sherlock-project:masterfrom
ashvinctrl:fix/globvar-instance-variable

Conversation

@ashvinctrl

Copy link
Copy Markdown

Summary

Fixes #2990

QueryNotifyPrint used a module-level globvar = 0 as its result counter. Because the global was never reset, scanning multiple usernames in one invocation (sherlock user1 user2) caused finish() to print a cumulative total across all usernames rather than a per-username count.

finish() also called self.countResults() - 1 — which incremented the counter one extra time before subtracting 1 — a fragile off-by-one workaround that breaks completely across multiple scans.

Changes

  • sherlock_project/notify.py: remove module-level globvar; add self._result_count = 0 in QueryNotifyPrint.__init__; countResults() now increments the instance variable; finish() reads self._result_count directly (no spurious extra increment)
  • tests/test_notify.py: new test file verifying counter starts at zero, increments only on CLAIMED, and that two independent instances never share state

Test plan

  • pytest tests/test_notify.py — all new tests pass
  • pytest — full suite green
  • sherlock user1 user2 — each username shows its own independent count

The module-level `globvar` in notify.py persisted across all username
scans in a single process, causing `finish()` to print a cumulative
count instead of a per-username count. Additionally, `finish()` called
`self.countResults() - 1` which incremented the counter one extra time
before subtracting 1 — a fragile pattern that masked the off-by-one.

Replace `globvar` with `self._result_count = 0` initialised in
`__init__`. Each `QueryNotifyPrint` instance now tracks its own scan
independently and `finish()` reads the counter directly without an
extra increment.

Fixes sherlock-project#2990
@ashvinctrl ashvinctrl requested a review from ppfeister as a code owner June 10, 2026 06:09
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.

fix: result counter accumulates across usernames due to module-level global

1 participant