Skip to content

build: fix typos in NAT-PMP detection block of configure.ac#447

Open
JSanchezFDZ wants to merge 1 commit into
Raptor3um:developfrom
JSanchezFDZ:fix/natpmp-link
Open

build: fix typos in NAT-PMP detection block of configure.ac#447
JSanchezFDZ wants to merge 1 commit into
Raptor3um:developfrom
JSanchezFDZ:fix/natpmp-link

Conversation

@JSanchezFDZ

Copy link
Copy Markdown

Summary

Fix two typos in the NAT-PMP detection block of configure.ac that cause --disable-wallet builds (and likely --without-natpmp requests on systems with libnatpmp available) to either link-fail or silently misbehave.

The bug

The dnl Enable NAT-PMP support block (lines 1569-1595 on develop) is a copy of the equivalent UPnP block immediately above it, but with two introduced typos:

  1. Line 1571if test "$have_natpmp" = "yes"; then inverts the disable/enable branches. The matching UPnP version (line 1543) reads if test "$have_miniupnpc" = "no"; then. The block decides what to do when the library was not found; with the typo it instead enters that branch when the library was found, so the auto-detect path runs the disable path on a successful detection and vice versa.

  2. Line 1578if test "$use_natpmp" != "no"l; then. The trailing l is a stray character. The shell evaluates "$use_natpmp" != "no"l which is always true (no value of $use_natpmp ever equals the literal string "no"l). The matching UPnP version (line 1550) correctly reads if test "$use_upnp" != "no"; then.

The compounded effect of the two typos: USE_NATPMP ends up AC_DEFINE'd (so mapport.cpp compiles in the NAT-PMP code path, since it uses #ifdef USE_NATPMP which only checks for defined-ness, not value) while at the same time NATPMP_LIBS ends up empty (so -lnatpmp is not on the link line). The result on --disable-wallet builds of develop HEAD (989ec2e):

$ ./configure --disable-bench --without-gui --disable-wallet
...
checking for natpmp.h... yes
checking for initnatpmp in -lnatpmp... yes
...
$ make raptoreumd
...
/usr/bin/ld: libraptoreum_server.a(libraptoreum_server_a-mapport.o):
  in function `ProcessNatpmp()':
./src/mapport.cpp:95: undefined reference to `readnatpmpresponseorretry'
./src/mapport.cpp:137: undefined reference to `sendnewportmappingrequest'
./src/mapport.cpp:64:  undefined reference to `sendpublicaddressrequest'
collect2: error: ld returned 1 exit status

(The reason --enable-wallet builds happen to escape the failure on this host is irrelevant link-order luck — the underlying bug is the same in both configurations.)

Fix

Make the NAT-PMP block mirror the UPnP block character-for-character (modulo the rename miniupnpcnatpmp / upnpnatpmp):

  • "yes""no" on the outer if test.
  • Drop the stray l after "no" on the inner if test.
  • (Cosmetic) determinedetermines in the AC_DEFINE_UNQUOTED description string, matching the UPnP equivalent.

Test plan

Verified on develop HEAD (989ec2e) with build prerequisites: ./autogen.sh && CONFIG_SITE=depends/x86_64-pc-linux-gnu/share/config.site.

  • Before patch, ./configure --disable-bench --without-gui --disable-wallet:

    • raptoreum-config.h contains #define USE_NATPMP 0 (a defined-but-zero value).
    • Makefile has NATPMP_LIBS = (empty).
    • make raptoreumd fails with the link errors quoted above.
  • After patch, same configure:

    • raptoreum-config.h contains /* #undef USE_NATPMP */.
    • make raptoreumd builds successfully. Daemon starts, --help works.
  • After patch, ./configure ... --enable-wallet --with-incompatible-bdb: still builds and runs cleanly. The --with-natpmp / --without-natpmp flags behave as documented.

Why this matters

  • CI configurations and downstream packagers that build with --disable-wallet (headless nodes, masternode-only builds, future Guix-deterministic builds) hit the link failure today on develop.
  • The typo means the auto-detect path silently does the wrong thing even when both flags are left at their defaults — depending on link order and which TU references which natpmp symbol first, the resulting binary may either fail to link, compile out NAT-PMP support when the user wanted it, or compile it in when they didn't.
  • Pure-textual fix, no behaviour change to working configurations.

Related

The `dnl Enable NAT-PMP support` block is a copy of the equivalent
UPnP block immediately above it, with two introduced typos that
compound:

  * Line 1571: `if test "$have_natpmp" = "yes"` inverts the
    disable/enable branches. The matching UPnP version reads
    `if test "$have_miniupnpc" = "no"`. The block decides what to do
    when the library is NOT found; with the typo it instead enters
    that branch when the library WAS found, so on a successful
    detection it disables NAT-PMP and on a failed detection it tries
    to enable it.

  * Line 1578: `if test "$use_natpmp" != "no"l` — stray trailing `l`.
    The shell evaluates `"$use_natpmp" != "no"l` which is always
    true (no value ever equals the literal string `"no"l`). The
    UPnP equivalent correctly reads `!= "no"`.

The compounded effect: `USE_NATPMP` ends up `AC_DEFINE`'d even when
the user requested `--without-natpmp` (so `mapport.cpp` compiles in
the NAT-PMP code path, since it gates on `#ifdef USE_NATPMP` which
only checks for defined-ness, not value) while at the same time
`NATPMP_LIBS` stays empty (no `-lnatpmp` on the link line). The
result is an undefined-reference link error against
`readnatpmpresponseorretry`, `sendnewportmappingrequest`, and
`sendpublicaddressrequest` in `libraptoreum_server.a(mapport.o)`.

Also fix `determine` -> `determines` in the `AC_DEFINE_UNQUOTED`
description string, matching the UPnP equivalent.

Verified by building raptoreumd with `--disable-wallet
--disable-bench --without-gui` on Ubuntu 22.04 / GCC 11.4 against
develop HEAD: prior to this commit the daemon fails to link, after
it links cleanly (with `USE_NATPMP` correctly left undefined when
the depends/-shipped `config.site` opts out of NAT-PMP).
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.

1 participant