Skip to content

Fix NameError in intelmqdump when loading global settings fails - #2723

Open
cristianchiriac wants to merge 1 commit into
certtools:developfrom
cristianchiriac:fix/intelmqdump-undefined-defaults
Open

cristianchiriac wants to merge 1 commit into
certtools:developfrom
cristianchiriac:fix/intelmqdump-undefined-defaults

Conversation

@cristianchiriac

@cristianchiriac cristianchiriac commented Sep 17, 2026

Copy link
Copy Markdown

Fixes #2702.

Bug

In intelmq/bin/intelmqdump.py, main() tries to load global settings to determine the log level:

try:
    defaults = utils.get_global_settings()
except Exception:
    log_level = DEFAULT_LOGGING_LEVEL

If get_global_settings() raises (incomplete setup, e.g. a dev install before running intelmqsetup, or a deleted runtime config), defaults is never assigned — but the very next block unconditionally calls defaults.get(...), so instead of failing with the real, informative exception the tool crashes with a confusing NameError: name 'defaults' is not defined, exactly as described in the issue.

Fix

Set defaults = {} in the except block, matching the fix suggested in the issue.

Note: main() calls get_global_settings() again, unguarded, further down (to enumerate bots and their dump locations). If the setup is genuinely and persistently broken, that second call still legitimately fails — this fix doesn't make the tool run without any config, it just replaces the confusing internal NameError with the real underlying exception (or lets the tool proceed normally, if the first failure was transient).

Test plan

  • Added test_incomplete_setup_does_not_raise_nameerror, mocking get_global_settings to raise and asserting specifically that main() doesn't raise NameError — any other exception from later in main() (the genuinely-broken-setup case above) is expected and not what the test guards against.
  • Verified the crash and fix in isolation (intelmqdump.py imports fcntl and is Unix-only, and I don't have a Linux environment set up to run the full suite here) — reproduced the exact NameError from the unpatched try/except logic, confirmed it's gone after the one-line fix.

Fixes certtools#2702. In an incomplete setup (dev install before running
intelmqsetup, or a deleted runtime config), utils.get_global_settings()
raises, but the except block only sets log_level and never assigns
defaults. The very next line calls defaults.get(...), crashing with
NameError instead of failing with the real underlying exception (or
proceeding, if the failure was transient).

Set defaults = {} in the except block, and add a regression test that
runs main() with get_global_settings() forced to raise, asserting
specifically that no NameError occurs. Note main() calls
get_global_settings() again, unguarded, further down (to enumerate
bots) — if the setup is genuinely and persistently broken, that call
still legitimately fails; this fix only replaces the confusing
NameError with the real, informative exception.
@cristianchiriac
cristianchiriac force-pushed the fix/intelmqdump-undefined-defaults branch from f35eb8c to dfd28f2 Compare September 17, 2026 11:00
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.

intelmqdump: exception when loading defaults fails

1 participant