blobmsg: use flexible-array member in blobmsg_name() - #50
Closed
micpf wants to merge 1 commit into
Closed
Conversation
blobmsg_name() returned (const char *)(hdr + 1), i.e. a pointer to
the byte immediately after struct blobmsg_hdr. GCC's stringop
analysis treats that region as size 0, so any caller that passes the
result to strcmp()/strlen()/etc. under -Wall -Wstringop-overread
triggers a false-positive diagnostic. For example, building uhttpd
(which uses -Wall -Werror) on aarch64 glibc with GCC 12.3.0 fails
with:
client.c:302:22: error: 'strcmp' reading 1 or more bytes from a
region of size 0 [-Werror=stringop-overread]
302 | if (!strcmp(blobmsg_name(cur), "URL"))
Return hdr->name instead. The flexible array member has unknown
size in GCC's object-size model, so no warning is emitted. The
generated pointer is identical.
Signed-off-by: Michael Pfeifroth <micpf@westermo.com>
Member
|
Applied, thanks. |
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
`blobmsg_name()` currently returns `(const char *)(hdr + 1)`, a pointer to the byte immediately after `struct blobmsg_hdr`. GCC's `__builtin_object_size` treats that region as size 0, so any caller passing the result to a string function (`strcmp`, `strlen`, `strchr`, …) under `-Wall -Wstringop-overread` gets a false-positive diagnostic.
Concrete example: building `uhttpd` (which uses `-Wall -Werror` in its CMakeLists.txt) on aarch64 glibc with GCC 12.3.0 fails:
```
client.c:302:22: error: 'strcmp' reading 1 or more bytes from a region of size 0
[-Werror=stringop-overread]
302 | if (!strcmp(blobmsg_name(cur), "URL"))
```
Fix
Return `hdr->name` (the flexible-array member) instead of `(hdr + 1)`. GCC treats flexible arrays as having unknown size, so the false positive disappears. The resulting pointer value is identical - purely a source-level change.
No behavioral change, no ABI change.