libtom / libtomcrypt

LibTomCrypt is a fairly comprehensive, modular and portable cryptographic toolkit that provides developers with a vast array of well known published block ciphers, one-way hash functions, chaining modes, pseudo-random number generators, public key cryptography and a plethora of other routines.
https://www.libtom.net
Other
1.55k stars 457 forks source link

gcc 10 warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] #555

Closed karel-m closed 3 years ago

karel-m commented 3 years ago

Two places:

The warning (gcc version 10.2.0):

gcc -Iltm -Iltc/headers -DLTC_SOURCE -DLTC_NO_TEST -DLTC_NO_PROTOTYPES -DLTM_DESC -DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__
    -D_GNU_SOURCE -ggdb -O2 -pipe -Wall -Werror=format-security -D_FORTIFY_SOURCE=2 -fstack-protector-strong
    --param=ssp-buffer-size=4 -fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/build=/usr/src/debug/perl-5.30.3-1
    -fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/src/perl-5.30.3=/usr/src/debug/perl-5.30.3-1 -fwrapv
    -fno-strict-aliasing   -O3 -DARGTYPE=4 -c ltc/encauth/ccm/ccm_add_nonce.c -o ltc/encauth/ccm/ccm_add_nonce.o
ltc/encauth/ccm/ccm_add_nonce.c: In function ‘ccm_add_nonce’:
ltc/encauth/ccm/ccm_add_nonce.c:58:21: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   58 |       ccm->PAD[x++] = (unsigned char)((len >> 24) & 255);
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ltc/headers/tomcrypt.h:82,
                 from ltc/headers/tomcrypt_private.h:4,
                 from ltc/encauth/ccm/ccm_add_nonce.c:3:
ltc/headers/tomcrypt_mac.h:408:24: note: at offset [16, 47] to object ‘PAD’ with size 16 declared here
  408 |    unsigned char       PAD[16],
      |                        ^~~

gcc -Iltm -Iltc/headers -DLTC_SOURCE -DLTC_NO_TEST -DLTC_NO_PROTOTYPES -DLTM_DESC -DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__
    -D_GNU_SOURCE -ggdb -O2 -pipe -Wall -Werror=format-security -D_FORTIFY_SOURCE=2 -fstack-protector-strong
    --param=ssp-buffer-size=4 -fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/build=/usr/src/debug/perl-5.30.3-1
    -fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/src/perl-5.30.3=/usr/src/debug/perl-5.30.3-1 -fwrapv
    -fno-strict-aliasing   -O3 -DARGTYPE=4 -c ltc/encauth/ccm/ccm_memory.c -o ltc/encauth/ccm/ccm_memory.o
ltc/encauth/ccm/ccm_memory.c: In function ‘ccm_memory’:
ltc/encauth/ccm/ccm_memory.c:161:17: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  161 |        PAD[x++] = (unsigned char)((len >> 24) & 255);
      |        ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ltc/encauth/ccm/ccm_memory.c:43:19: note: at offset [15, 46] to object ‘PAD’ with size 16 declared here
   43 |    unsigned char  PAD[16], ctr[16], CTRPAD[16], ptTag[16], b, *pt_real;
      |                   ^~~
ltc/encauth/ccm/ccm_memory.c:161:17: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  161 |        PAD[x++] = (unsigned char)((len >> 24) & 255);
      |        ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ltc/encauth/ccm/ccm_memory.c:43:19: note: at offset [16, 47] to object ‘PAD’ with size 16 declared here
   43 |    unsigned char  PAD[16], ctr[16], CTRPAD[16], ptTag[16], b, *pt_real;
      |                   ^~~
jamuir commented 3 years ago

wouldn't valgrind catch memory issues like these? I could try running the tests using valgrind if that would be helpful.

karel-m commented 3 years ago

The branch cleanup-and-fixes fixed this issue