Skip to content

Fix result_parser: null body guard, explicit dispatch, TypeError messages, dead code - #152

Open
t0kubetsu wants to merge 1 commit into
D4-project:mainfrom
t0kubetsu:fix/result-parser
Open

Fix result_parser: null body guard, explicit dispatch, TypeError messages, dead code#152
t0kubetsu wants to merge 1 commit into
D4-project:mainfrom
t0kubetsu:fix/result-parser

Conversation

@t0kubetsu

Copy link
Copy Markdown
Contributor

Summary

Fixes #145. Three correctness bugs and two code-quality issues in result_parser.py.

Changes

Null body guard

parse_json chained .get("body").get(...) without null guards. Any document with a missing or None body key raised TypeError/AttributeError, crashing the export tick. Now extracted to body = doc.get("body") or {} and ports = body.get("ports") or [] at the top of the function.

Explicit dispatch dict

globals()[action] was used to look up parser functions. Replaced with _PARSER_DISPATCH, a module-level dict explicitly mapping each ALLOW-listed name to its function. Prevents silent divergence between ALLOW and globals(). Added a hsh stub (NotImplementedError) so the table is complete.

TypeError messages

Bare raise TypeError (no message, no instance) at lines 621 and 633 replaced with descriptive messages. Also fixed ruff E713: not x in yx not in y.

Loop variable shadowing

Loop variable script was immediately rebound to the dict value on the next line, producing a confusing for script in body: ... script = body.get(script) pattern. Renamed to script_key/script_data.

Dead code removal

insensitive() function removed — not in ALLOW, not imported anywhere, unreachable since v0.2606.0.

Test plan

  • Submit a scan result with body=None — verify export tick does not crash
  • Submit a scan result with missing ports key — verify graceful handling
  • Verify all 11 parser actions in ALLOW remain callable via _PARSER_DISPATCH

…ages, dead code removal

- Add `body = doc.get("body") or {}` and `ports = body.get("ports") or []`
  guards in `parse_json` to prevent AttributeError/TypeError on missing body
- Replace `globals()[action]` with `_PARSER_DISPATCH` explicit dict for safe,
  auditable parser function lookup; add `hsh` stub for completeness
- Replace bare `raise TypeError` with descriptive messages; fix E713 style
  (`not x in y` -> `x not in y`)
- Rename loop variable `script` to `script_key`/`script_data` to eliminate
  shadowing of the iteration variable
- Remove dead `insensitive()` function (not in ALLOW, not imported anywhere)

Fixes D4-project#145
@t0kubetsu
t0kubetsu force-pushed the fix/result-parser branch from 8fe4d67 to 91764bf Compare June 2, 2026 09:15
@t0kubetsu

Copy link
Copy Markdown
Contributor Author

Fixed hsh() stub: changed NotImplementedError to return {} — hsh is in default_parsing so raising would crash the export tick for documents with http-header.output.

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.

HIGH: result_parser.py — null body crash on malformed docs, globals() dispatch drift, dead code

1 participant