Skip to content

blobmsg: use flexible-array member in blobmsg_name() - #50

Closed
micpf wants to merge 1 commit into
openwrt:masterfrom
micpf:blobmsg-flexible-array-member
Closed

blobmsg: use flexible-array member in blobmsg_name()#50
micpf wants to merge 1 commit into
openwrt:masterfrom
micpf:blobmsg-flexible-array-member

Conversation

@micpf

@micpf micpf commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

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.

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>
@nbd168

nbd168 commented Jul 21, 2026

Copy link
Copy Markdown
Member

Applied, thanks.

@nbd168 nbd168 closed this Jul 21, 2026
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.

2 participants