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

Warning -Warray-bounds on H_ns in src/util/srp.cpp #10238

Closed
darnuria opened this issue Jul 29, 2020 · 1 comment · Fixed by #12015
Closed

Warning -Warray-bounds on H_ns in src/util/srp.cpp #10238

darnuria opened this issue Jul 29, 2020 · 1 comment · Fixed by #12015

Comments

@darnuria
Copy link

darnuria commented Jul 29, 2020

Minetest version

Commit: 3ce03d1
Type: Build issue / warning

OS / Hardware

Operating system: Ubuntu 18.04
Compiler: Gcc/G++ (Ubuntu 10.1.0-2ubuntu1~18.04) 10.1.0

Summary

Got this compilation warning on build with gcc 10.

Steps to reproduce

Compile with gcc 10.

[ 31%] Building CXX object src/CMakeFiles/minetest.dir/version.cpp.o
In file included from /usr/include/string.h:494,
                 from /usr/include/c++/10/cstring:42,
                 from minetest/src/util/srp.cpp:43:
In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘int calculate_x(__mpz_struct*, SRP_HashAlgorithm, const unsigned char*, size_t, const char*, const unsigned char*, size_t)’ at minetest/src/util/srp.cpp:432:8:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:34:33: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ forming offset [64, 4294967294] is out of the bounds [0, 64] of object ‘ucp_hash’ with type ‘unsigned char [64]’ [-Warray-bounds]
   34 |   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
minetest/src/util/srp.cpp: In function ‘int calculate_x(__mpz_struct*, SRP_HashAlgorithm, const unsigned char*, size_t, const char*, const unsigned char*, size_t)’:
minetest/src/util/srp.cpp:443:16: note: ‘ucp_hash’ declared here
  443 |  unsigned char ucp_hash[SHA512_DIGEST_LENGTH];
      |                ^~~~~~~~

Link to code:

https://github.com/minetest/minetest/blob/master/src/util/srp.cpp#L424-L437

Previous bug on this line

#6855

@darnuria darnuria added the Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible label Jul 29, 2020
@SmallJoker SmallJoker added Low priority Code quality and removed Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible labels Jul 29, 2020
@numberZero
Copy link
Contributor

Finally proper compiler warning (on my system it was reporting -1 as the out of bounds index).
The code here assumes that hash_length(alg) <= SHA512_DIGEST_LENGTH for each and every hashing algorithm that may ever reach the point. The only supported algorithm seems to be SHA256, so... that seems to be false alert, if treated literally; OTOH that should be clear from the code (like defining and using MAX_DIGEST_LENGTH or so).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants