Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zebra: fix compilation with GCC14 #16155

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

httpstorm
Copy link
Contributor

Fixes:

zebra/zebra_netns_notify.c: In function 'zebra_ns_ready_read':
zebra/zebra_netns_notify.c:266:40: error: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
  266 |         if (strmatch(VRF_DEFAULT_NAME, basename(netnspath))) {
      |                                        ^~~~~~~~

Fixed by including libgen.h, then since basename may modify its parameter, allocate a copy on the stack, using strdupa, and pass the temporary string to basename.

According to the man page for basename:

With glibc, one gets the POSIX version of basename() when <libgen.h> is included, and the GNU version otherwise.
The POSIX version of basename may modify the contents of path, so we should to pass a copy when calling this function.

Please let me know if any changes are needed. I created the fix based on a similar fix I found on OpenWRT for another project.
Build tested: OpenWRT firmware for WRT3200ACM, using gcc-14, compiled on macOS 14.5 host.
Applies to: master, 9.0, 10.0.

[1] https://man7.org/linux/man-pages/man3/basename.3.html

Maintainer: @eqvinox
@sri-mohan1 @donaldsharp @Pdoijode @rzalamena @ton31337 @idryzhov @qlyoung @robimarko @neheb

Fixes:
zebra/zebra_netns_notify.c: In function 'zebra_ns_ready_read':
zebra/zebra_netns_notify.c:266:40: error: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
  266 |         if (strmatch(VRF_DEFAULT_NAME, basename(netnspath))) {
      |                                        ^~~~~~~~

Fixed by including libgen.h, then since basename may modify its
parameter, allocate a copy on the stack, using strdupa, and pass the
temporary string to basename.

According to the man page for basename:
With glibc, one gets the POSIX version of basename() when
<libgen.h> is included, and the GNU version otherwise.

The POSIX version of basename may modify the contents of path,
so we should to pass a copy when calling this function.

[1] https://man7.org/linux/man-pages/man3/basename.3.html

Signed-off-by: Georgi Valkov <[email protected]>
@riw777 riw777 requested a review from davischw June 4, 2024 15:12
@donaldsharp donaldsharp merged commit c5bb472 into FRRouting:master Jun 5, 2024
11 checks passed
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.

2 participants