~sircmpwn/gmni#43: 
gmni: build error [-Werror=stringop-overflow=]

Thanks for fixing #42. I however encountered another warning that became an error further down, does this have something to do with my setup?

unpacking sources
unpacking source archive /nix/store/7l48rf19chil19zf3pfwfk5wr4gbcsfj-source
source root is source
patching sources
configuring
configure flags: --prefix=/nix/store/r97vkpn99f4b9rvqndw6q9ki8lbzrqg9-gmni
Checking for -g... yes
Checking for -std=c11... yes
Checking for -D_XOPEN_SOURCE=700... yes
Checking for -Wall... yes
Checking for -Wextra... yes
Checking for -Werror... yes
Checking for -pedantic... yes
Checking for OpenSSL... OK
Checking for OpenSSL... OK
Checking for scdoc... yes
Creating .build/config.mk... done
building
build flags: SHELL=/nix/store/k8p54jg8ipvnfz435mayf5bnqhw4qqap-bash-4.4-p23/bin/bash
CC      src/client.o
CC      src/escape.o
CC      src/gmni.o
CC      src/tofu.o
CC      src/url.o
CC      src/util.o
In file included from /nix/store/a2n8nrsf215x01a7fv8l94crdjwf69pa-glibc-2.32-dev/include/string.h:519,
                 from src/util.c:8:
In function 'strncat',
    inlined from 'download_resp' at src/util.c:77:3:
/nix/store/a2n8nrsf215x01a7fv8l94crdjwf69pa-glibc-2.32-dev/include/bits/string_fortified.h:137:10: error: '__builtin___strncat_chk' specified bound 4096 equals destination size [-Werror=stringop-overflow=]
  137 |   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:24: src/util.o] Error 1
Status
RESOLVED FIXED
Submitter
~dmedinag
Assigned to
No-one
Submitted
7 months ago
Updated
5 months ago
Labels
No labels applied.

~dmedinag 7 months ago

I found this, that could be related. I'm going to try and apply the suggestions in the question to see if it works.

~dmedinag 7 months ago

This patch does the trick for me, but I'm not sure it is correct, is the default value for result the right one? There was an error in the build claiming result may not have been initialized in gmnlm.c

diff --git a/src/gmnlm.c b/src/gmnlm.c
index 2fba84e..f7d7e38 100644
--- a/src/gmnlm.c
+++ b/src/gmnlm.c
@@ -479,7 +479,7 @@ do_requests(struct browser *browser, struct gemini_response *resp)
 static enum prompt_result
 do_prompts(const char *prompt, struct browser *browser)
 {
-       enum prompt_result result;
+       enum prompt_result result = PROMPT_QUIT;
        fprintf(browser->tty, "%s", prompt);
 
        size_t l = 0;
@@ -609,7 +609,7 @@ do_prompts(const char *prompt, struct browser *browser)
                if (in[1] != '\0' && !isspace(in[1])) break;
                struct gemini_response resp;
                char url[1024] = {0};
-               strncpy(&url[0], browser->plain_url, sizeof(url));
+               strncpy(&url[0], browser->plain_url, sizeof(url) - 1);
                // XXX: may affect history, do we care?
                enum gemini_result res = do_requests(browser, &resp);
                if (res != GEMINI_OK) {
@@ -624,7 +624,7 @@ do_prompts(const char *prompt, struct browser *browser)
                result = PROMPT_AGAIN;
                goto exit;
        case '|':
-               strncpy(&url[0], browser->plain_url, sizeof(url));
+               strncpy(&url[0], browser->plain_url, sizeof(url) - 1);
                res = do_requests(browser, &resp);
                if (res != GEMINI_OK) {
                        fprintf(stderr, "Error: %s\n",
diff --git a/src/util.c b/src/util.c
index 0a479af..3578d9e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -74,8 +74,7 @@ download_resp(FILE *out, struct gemini_response resp, const char *path,
                path = "./";
        }
        if (path[strlen(path)-1] == '/') {
-               strncat(strncpy(&buf[0], path, sizeof(buf)), basename(url),
-                       sizeof(buf));
+               strncat(strncpy(&buf[0], path, sizeof(buf) - 1), basename(url), sizeof(buf) - 1);
                path = &buf[0];
        }
        FILE *f = fopen(path, "w");

~sircmpwn 7 months ago

Please send your patch to the mailing list using git send-email. The bug tracker is not for patch discussion.

~sircmpwn REPORTED FIXED 5 months ago

Register here or Log in to comment, or comment via email.