Skip to content

bgpd: fix return NULL in bool function ecommunity_node_target_match - #22273

Merged
riw777 merged 1 commit into
FRRouting:masterfrom
guoguojia2021:fix/bgpd-ecommunity-return-null
Jun 9, 2026
Merged

bgpd: fix return NULL in bool function ecommunity_node_target_match#22273
riw777 merged 1 commit into
FRRouting:masterfrom
guoguojia2021:fix/bgpd-ecommunity-return-null

Conversation

@guoguojia2021

Copy link
Copy Markdown
Contributor

ecommunity_node_target_match() is declared as returning bool, but the early-exit path for empty or missing ecommunity uses 'return NULL'.

NULL is a pointer constant ((void*)0), not a boolean value. Returning a pointer type from a bool function relies on an implicit pointer-to- integer conversion, which is undefined behavior per the C standard (C11 6.8.6.4). While most compilers implicitly convert NULL to false (0), this is not guaranteed and produces warnings under -Wpedantic or -Wint-conversion, which can break builds with -Werror enabled.

The function already declares 'bool match = false' and returns match at the end, so the intent of the early-exit is clearly to return false when the ecommunity is empty or NULL.

Change 'return NULL' to 'return false' to match the function's return type and eliminate the undefined behavior.

ecommunity_node_target_match() is declared as returning bool, but the
early-exit path for empty or missing ecommunity uses 'return NULL'.

NULL is a pointer constant ((void*)0), not a boolean value. Returning
a pointer type from a bool function relies on an implicit pointer-to-
integer conversion, which is undefined behavior per the C standard
(C11 6.8.6.4). While most compilers implicitly convert NULL to false
(0), this is not guaranteed and produces warnings under -Wpedantic or
-Wint-conversion, which can break builds with -Werror enabled.

The function already declares 'bool match = false' and returns match
at the end, so the intent of the early-exit is clearly to return
false when the ecommunity is empty or NULL.

Change 'return NULL' to 'return false' to match the function's return
type and eliminate the undefined behavior.

Signed-off-by: guozhongfeng.gzf <guozhongfeng.gzf@alibaba-inc.com>
@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR corrects an improper return NULL in ecommunity_node_target_match, a function declared to return bool. Returning a pointer constant from a boolean function relies on an implicit conversion that is technically undefined behavior in C11 and can trigger warnings under strict compiler flags.

  • Replaces return NULL with return false on the early-exit guard for a null or empty ecommunity, matching the function's declared return type and eliminating any implicit pointer-to-integer conversion.

Confidence Score: 5/5

Safe to merge β€” the one-line change corrects a type mismatch that had no observable behavioral difference on mainstream compilers but was technically non-conforming.

The change is a trivial, well-scoped correction: the early return in ecommunity_node_target_match now uses false instead of NULL, which on every real compiler produced the same zero/false result. The fix removes a latent conformance issue with no risk of introducing new bugs.

No files require special attention.

Important Files Changed

Filename Overview
bgpd/bgp_ecommunity.c Single-line fix replacing return NULL with return false in the bool-typed function ecommunity_node_target_match, eliminating an implicit pointer-to-integer conversion.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[ecommunity_node_target_match called] --> B{ecom is NULL or ecom->size == 0?}
    B -- "Yes (before)" --> C["return NULL ❌ (implicit pointer-to-int)"]
    B -- "Yes (after)" --> D["return false βœ… (correct bool)"]
    B -- No --> E[Iterate over ecommunity entries]
    E --> F{type == ENCODE_IP && sub_type == NODE_TARGET?}
    F -- Yes --> G{IPV4_ADDR_SAME match?}
    G -- Yes --> H[match = true]
    G -- No --> I[continue]
    F -- No --> I
    H --> J[return match]
    I --> J
Loading

Reviews (1): Last reviewed commit: "bgpd: fix return NULL in bool function e..." | Re-trigger Greptile

@ton31337

ton31337 commented Jun 9, 2026

Copy link
Copy Markdown
Member

@Mergifyio backport stable/10.6 stable/10.5 stable/10.4 stable/10.3

@mergify

mergify Bot commented Jun 9, 2026

Copy link
Copy Markdown

backport stable/10.6 stable/10.5 stable/10.4 stable/10.3

βœ… Backports have been created

Details

@riw777 riw777 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@riw777
riw777 merged commit 293288d into FRRouting:master Jun 9, 2026
25 checks passed
riw777 added a commit that referenced this pull request Jun 9, 2026
bgpd: fix return NULL in bool function ecommunity_node_target_match (backport #22273)
riw777 added a commit that referenced this pull request Jun 9, 2026
bgpd: fix return NULL in bool function ecommunity_node_target_match (backport #22273)
riw777 added a commit that referenced this pull request Jun 9, 2026
bgpd: fix return NULL in bool function ecommunity_node_target_match (backport #22273)
riw777 added a commit that referenced this pull request Jun 9, 2026
bgpd: fix return NULL in bool function ecommunity_node_target_match (backport #22273)
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.

3 participants