client: fix compilation error with GCC 12
authorChristian 'Ansuel' Marangi <ansuelsmth@gmail.com>
Wed, 1 Jun 2022 12:25:32 +0000 (14:25 +0200)
committerChristian 'Ansuel' Marangi <ansuelsmth@gmail.com>
Wed, 1 Jun 2022 12:29:11 +0000 (14:29 +0200)
Using GCC 12 on an aarch64 target the following compilation error is
printed.
ninja: Entering directory `/home/ansuel/openwrt/build_dir/target-aarch64_cortex-a53_musl/uhttpd-2022-02-07-2f8b1360'
[1/2] Building C object CMakeFiles/uhttpd.dir/client.c.o
FAILED: CMakeFiles/uhttpd.dir/client.c.o
/home/ansuel/openwrt/staging_dir/host/bin/ccache /home/ansuel/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-12.1.0_musl/bin/aarch64-openwrt-linux-musl-gcc -DHAVE_LUA -DHAVE_SHADOW -DHAVE_TLS -DHAVE_UBUS -DHAVE_UCODE -D_FILE_OFFSET_BITS=64  -Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/ansuel/openwrt/build_dir/target-aarch64_cortex-a53_musl/uhttpd-2022-02-07-2f8b1360=uhttpd-2022-02-07-2f8b1360 -Wformat -Werror=format-security -DPIC -fPIC -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG   -Os -Wall -Werror -Wmissing-declarations --std=gnu99 -g3 -MD -MT CMakeFiles/uhttpd.dir/client.c.o -MF CMakeFiles/uhttpd.dir/client.c.o.d -o CMakeFiles/uhttpd.dir/client.c.o -c /home/ansuel/openwrt/build_dir/target-aarch64_cortex-a53_musl/uhttpd-2022-02-07-2f8b1360/client.c
In function 'tls_redirect_check',
    inlined from 'client_header_complete' at client.c:306:7,
    inlined from 'client_parse_header' at client.c:338:3,
    inlined from 'client_header_cb' at client.c:502:2:
client.c:269:22: error: 'strcmp' reading 1 or more bytes from a region of size 0 [-Werror=stringop-overread]
  269 |                 if (!strcmp(blobmsg_name(cur), "URL"))
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.

Fix this by using the strncmp variant.

Signed-off-by: Christian 'Ansuel' Marangi <ansuelsmth@gmail.com>
client.c

index 2be8f22a8eef89f7398c785ac21e6692e8a80676..06336eb39046a18da75981a46e248793ed22d3a9 100644 (file)
--- a/client.c
+++ b/client.c
@@ -263,10 +263,10 @@ static bool tls_redirect_check(struct client *cl)
                return true;
 
        blob_for_each_attr(cur, cl->hdr.head, rem) {
-               if (!strcmp(blobmsg_name(cur), "host"))
+               if (!strncmp(blobmsg_name(cur), "host", 4))
                        host = blobmsg_get_string(cur);
 
-               if (!strcmp(blobmsg_name(cur), "URL"))
+               if (!strncmp(blobmsg_name(cur), "URL", 3))
                        url = blobmsg_get_string(cur);
 
                if (url && host)