Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: ‘%s’ directive output may be truncated writing up to 2511 bytes into a region of size between 875 and 966 #75

Open
gijzelaerr opened this issue Mar 13, 2018 · 1 comment

Comments

@gijzelaerr
Copy link

Hi! When i try to compile libs3 on a clean Ubuntu 18.04 I run into troubles:

λ  make
build/obj/request.do: Compiling dynamic object
src/request.c: In function ‘setup_request’:
src/request.c:1056:74: error: ‘%s’ directive output may be truncated writing up to 2511 bytes into a region of size between 875 and 966 [-Werror=format-truncation=]
             "Authorization: AWS4-HMAC-SHA256 Credential=%s,SignedHeaders=%s,Signature=%s",
                                                                          ^~
In file included from /usr/include/stdio.h:862:0,
                 from /usr/include/libxml2/libxml/tree.h:15,
                 from /usr/include/libxml2/libxml/parser.h:16,
                 from src/request.c:32:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 70 and 2736 bytes into a destination of size 1024
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/request.c: In function ‘request_api_initialize’:
src/request.c:1448:51: error: ‘%s’ directive output may be truncated writing up to 64 bytes into a region of size between 31 and 96 [-Werror=format-truncation=]
         snprintf(platform, sizeof(platform), "%s%s%s", utsn.sysname,
                                                   ^~
                  utsn.machine[0] ? " " : "", utsn.machine);
                                              ~~~~
In file included from /usr/include/stdio.h:862:0,
                 from /usr/include/libxml2/libxml/tree.h:15,
                 from /usr/include/libxml2/libxml/parser.h:16,
                 from src/request.c:32:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 1 and 130 bytes into a destination of size 96
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/request.c: In function ‘S3_generate_authenticated_query_string’:
src/request.c:1745:14: error: ‘%s’ directive output may be truncated writing up to 2511 bytes into a region of size between 170 and 329 [-Werror=format-truncation=]
              "X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=%s"
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/request.c:1749:14:
              computed.signedHeaders, computed.requestSignatureHex);
              ~~~~~~~~
src/request.c:1747:36: note: format string is defined here
              "&X-Amz-SignedHeaders=%s&X-Amz-Signature=%s",
                                    ^~
In file included from /usr/include/stdio.h:862:0,
                 from /usr/include/libxml2/libxml/tree.h:15,
                 from /usr/include/libxml2/libxml/parser.h:16,
                 from src/request.c:32:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 117 and 2851 bytes into a destination of size 428
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
GNUmakefile:223: recipe for target 'build/obj/request.do' failed
make: *** [build/obj/request.do] Error 1
@jharbott
Copy link

I did hit the same issue, seems the checks got stricter with the updated g++:

ubuntu@bionicle1:~/libs3$ g++ --version                                                                                                                                                                            
g++ (Ubuntu 7.3.0-16ubuntu3) 7.3.0                                                                                                                                                                                 
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ubuntu@bionicle1:~/libs3$

As a workaround you can just add an option to demote the error to a warning:

diff --git a/GNUmakefile b/GNUmakefile                                                                                                                                                                             
index c81537c..ab1324e 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -136,7 +136,7 @@ ifndef CFLAGS                                                                                                                                                                                  
     endif                                                                                                                                                                                                         
 endif
 
-CFLAGS += -Wall -Werror -Wshadow -Wextra \
+CFLAGS += -Wall -Werror -Wshadow -Wextra -Wno-format-truncation \
                  -Iinc \
           $(CURL_CFLAGS) $(LIBXML2_CFLAGS) \
           -DLIBS3_VER_MAJOR=\"$(LIBS3_VER_MAJOR)\" \

but in the long run better bounds checking might be needed.

jharbott added a commit to x-ion-de/stress3 that referenced this issue May 25, 2018
There is some stricter bounds checking related to snprintf() calls with
the updated compiler, causing issues when building e.g. on Ubuntu
Bionic, see [0]. Add a flag to ignore that check.

[0] bji/libs3#75
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

No branches or pull requests

2 participants