← Back to Pull requests

refactor(bindings): split newWafSymbols into a table and a loop (maat #6) #244

Closed
unknown closed this pull request without merging on Nov 17, 2026 14:39 UTC
View on GitHub
unknown unknown commented on Nov 12, 2026 16:20 UTC
Author

What and why

newWafSymbols (internal/bindings/libddwaf.go) had 20 copies of the same "resolve the symbol, return on error" block. maat reported 8 hits on it. This change replaces the 20 blocks with a table of 20 {name, uintptr} rows ((wafSymbols).table) and 1 loop.

No behavior change:

  • Same 20 symbols, in the same resolution order. The order decides which symbol the error names when more than 1 is missing.

  • The loop stops at the first error.

  • Same error text (failed to resolve libddwaf symbol %q: %w) and same %w wrapping.

  • Same return value on error. The loop stays inside newWafSymbols, so return syms, ... reads syms after the loop filled it.

  • The name and signature of newWafSymbols, the wafSymbols struct and waf_dl.go do not change.
  • Part of the maat assessment (item #6). Linear: DD-34.

    The new file internal/bindings/libddwaf_test.go has the first tests of this code:

  • TestWafSymbolsTable checks the name, the order and the target field of each row against a list copied from the code on main. It uses require.Same for the pointers, because require.Equal compares the pointed values and all fields are 0.

  • TestNewWafSymbolsMissingSymbol loads libc (linux) or libSystem (darwin), which has no libddwaf symbol. It checks the %w type, the exact text (it names the first symbol of the table), and that the returned syms is zero.
  • maat before / after (maat analyze ./... --output json --detail full, maat 0.5.0)

    | Scope | Before | After |
    |---|---|---|
    | Overall | 90 (base 89.54) | 90 (base 89.64) |
    | internal/bindings | 94 (base 93.94) | 95 (base 95.01) |
    | libddwaf.go | 84 | 100 |
    | libddwaf_test.go (new) | none | 100 |

    No new hit. The 8 removed hits, all on newWafSymbols:

    | Rule | Severity | Value |
    |---|---|---|
    | MAAT-CC-001 | error | cyclomatic complexity 22 |
    | MAAT-CC-002 | warning | cognitive complexity 20 |
    | MAAT-FUNC-002 | error | cyclomatic complexity 22 |
    | MAAT-FUNC-003 | warning | 43 SLOC |
    | MAAT-FUNC-006 | warning | 21 return statements |
    | MAAT-HALSTEAD-001 | warning | Halstead volume 1381.3 |
    | MAAT-MI-001 | error | maintainability index 39 |
    | MAAT-SLOC-001 | warning | 43 SLOC |

    Total hits: 199 → 191. The module hit MAAT-TEST-001 stays (16 → 18 test functions, 25% → 28%). The overall integer score stays at 90 (threshold 95).

    Checks done locally

    | Check | Result |
    |---|---|
    | go vet ./... | exit 0 |
    | go test -count=1 ./... (darwin/arm64) | pass |
    | CGO_ENABLED=0 go test -count=1 -tags ci,appsec ./internal/bindings/ (darwin/arm64) | pass |
    | GOEXPERIMENT=cgocheck2 CGO_ENABLED=1 go test -race -count=1 -tags ci ./internal/bindings/ (darwin/arm64) | pass |
    | golang:1.27-bookworm (linux/arm64, glibc), CGO_ENABLED=0 -tags ci,appsec, then CGO_ENABLED=1 -tags ci | pass, pass |
    | golang:1.27-alpine (linux/arm64, musl), CGO_ENABLED=0 -tags ci,appsec | pass |
    | Mutation 1: swap the pointers of 2 rows | TestWafSymbolsTable fails at entry 1 |
    | Mutation 2: swap the order of 2 rows | TestWafSymbolsTable fails at entry 6 |

    Both mutations were reverted.

    Order and mapping check against main (the name → field pairs of the 20 old if blocks vs. the new table, and vs. the golden list in the test): both diff commands print nothing (exit 0).

    Diff: 412 lines (+309 / -103) across 5 files Reviewer: eliottness Review duration: 7098m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 412 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.360
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #244"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.9% (MEDIUM) · Higher = larger blast radius
    44.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.7% · Safe to merge
    17.7%