Skip to content

ospf6d: only allow positive time strings#21928

Open
jeremie6wind wants to merge 1 commit into
FRRouting:masterfrom
jeremie6wind:master
Open

ospf6d: only allow positive time strings#21928
jeremie6wind wants to merge 1 commit into
FRRouting:masterfrom
jeremie6wind:master

Conversation

@jeremie6wind
Copy link
Copy Markdown

Set the number of seconds to 0 if it is negative.

Set the number of seconds to 0 if it is negative.

Signed-off-by: Jeremie Leska <jeremie.leska@6wind.com>
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 13, 2026

Greptile Summary

This PR fixes the timerstring macro in ospf6d/ospf6d.h to clamp negative tv_sec values to zero before formatting, preventing garbled or negative time strings when a timer has already fired or when time arithmetic yields a negative result.

  • Introduces a long long _sec local variable inside the do { } while(0) block — correctly scoped so it cannot leak or clash with outer variables.
  • All snprintf format arguments are updated to use _sec instead of (tv)->tv_sec, keeping the %lld specifiers consistent.

Confidence Score: 5/5

The change is safe to merge — it adds a one-line negative-value guard inside a well-contained macro block with no side effects on callers.

The fix is minimal and narrowly scoped: a long long _sec variable is declared inside the existing do { } while(0) block, so it cannot escape the macro or shadow outer names. The clamping logic is straightforward, the %lld format specifiers remain correct, and threadtimer_string already passes the result of timersub through timerstring, so it benefits from the fix automatically.

No files require special attention.

Important Files Changed

Filename Overview
ospf6d/ospf6d.h Adds negative-second guard in the timerstring macro by clamping tv_sec to 0 before formatting; logic and scoping are correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["timerstring(tv, buf, size)"] --> B["_sec = tv->tv_sec"]
    B --> C{_sec < 0?}
    C -- Yes --> D["_sec = 0"]
    C -- No --> E{_sec / 60 / 60 / 24 != 0?}
    D --> E
    E -- Yes --> F["snprintf: Dd HH:MM:SS"]
    E -- No --> G["snprintf: HH:MM:SS"]
Loading

Reviews (1): Last reviewed commit: "ospf6d: only allow positive time strings" | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant