cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
bfanchon
Level 2

Out of bound index in C/C++ methods

Hello,

I get the following warning when I compile sample C++ code:

In file included from License.h:15,
                 from License.cc:10:
License.cc: In static member function ‘static std::string License::_cryptFeature(const string&, size_t*)’:
License.cc:865:5: warning: ‘void* memcpy(void*, const void*, size_t)’ offset 160 is out of the bounds [0, 120] of object ‘lm_prikey’ with type ‘unsigned char [1][3][40]’ [-Warray-bounds]
  865 |     LM_CODE_GEN_INIT_NEW(&_code, ENCRYPTION_SEED1, ENCRYPTION_SEED2, l_priseedcnt, lm_prikey, lm_prisize);
      |     ^~~~~~~~~~~~~~~~~~~~
In file included from License.cc:16:
FlexNet/x64_lsb/lmprikey.h:4:22: note: ‘lm_prikey’ declared here
    4 | static unsigned char lm_prikey[1][3][40] = {{{0x0, 0x9f, 0x1d, 0xd6, 0x2d, 0xb, 0x3e, 0x75, 0x53, 0xf5, 0x14, 0x5c, 0xd2, 0x86, 0x9c},
      |                      ^~~~~~~~~

 

A close reading seems to validate this warning, and I suspect an typo in the LM_CODE_GEN_INIT / LM_CODE_GEN_INIT_NEW macros:

   for (pcnt = 0; pcnt <= (cnt); pcnt++)

As index starts from zero, the end condition should be pcnt < cnt (rather than pcnt <= cnt).

 

Do you validate this analysis ?

0 Kudos
(0) Replies