dhcpv6-ia: zero-initialize first_key to silence -Wmaybe-uninitialized - #409
Open
micpf wants to merge 1 commit into
Open
dhcpv6-ia: zero-initialize first_key to silence -Wmaybe-uninitialized#409micpf wants to merge 1 commit into
micpf wants to merge 1 commit into
Conversation
first_key[] is only read on the path guarded by first_key_valid, and
first_key_valid is only set to true after first_key has been populated
by memcpy(). The code is therefore correct, but GCC's uninitialized
analysis cannot correlate the boolean guard with the array's
initialization state.
With glibc's _FORTIFY_SOURCE enabled, memcpy() is expanded inline as
__builtin___memcpy_chk(), and on aarch64 the 16-byte copy is further
lowered to a single 128-bit access. GCC 12 then emits:
error: '*(__int128 unsigned *)(&first_key[0])' may be used
uninitialized [-Werror=maybe-uninitialized]
which -Werror in CMakeLists.txt turns into a build failure on
aarch64 glibc targets (e.g. NXP LS1046). musl and non-fortified
builds are unaffected because they don't inline the fortified
wrapper the same way.
Zero-initialize the buffer to silence the false positive. Runtime
behavior is unchanged: when first_key_valid is true, the buffer has
already been overwritten by memcpy(first_key, a->key, ...).
Signed-off-by: Michael Pfeifroth <micpf@westermo.com>
micpf
force-pushed
the
dhcpv6-ia-silence-maybe-uninitialized
branch
from
July 21, 2026 06:47
94f96d7 to
43b9aeb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Building odhcpd on an aarch64 glibc target (NXP LS1046, GCC 12.3.0) with
_FORTIFY_SOURCEenabled fails with:CMakeLists.txt sets
-Werror, so this turns the warning into a hard build failure.Analysis
The code is correct:
first_key[]is only read on the branch guarded byfirst_key_valid, andfirst_key_validis only set totrueaftermemcpy(first_key, a->key, sizeof(first_key)). GCC's-Wmaybe-uninitializedanalysis cannot correlate the boolean guard with the array's initialization state — a well-known limitation.The warning becomes visible only when three conditions coincide:
memcpyis expanded inline as__builtin___memcpy_chkviabits/string_fortified.h._FORTIFY_SOURCEenabled at the caller.__int128) access, exposing the correlation problem in the diagnostic simplifier.musl builds and non-fortified builds are unaffected because they don't inline the fortified wrapper the same way. That's why upstream CI hasn't hit this.
Fix
Zero-initialize
first_key[16]. Runtime behavior is unchanged — whenfirst_key_validis true, the buffer has already been overwritten bymemcpy(first_key, a->key, …). The added cost is one zeroing store on function entry.