]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
fips-prf: Add explicit bound check to avoid GCC 12 compile warning
authorTobias Brunner <tobias@strongswan.org>
Thu, 16 Jun 2022 16:18:26 +0000 (18:18 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 27 Jun 2022 12:09:11 +0000 (14:09 +0200)
GCC assumes this->b is zero (or may be zero) and spits out the following
warning (or error with -Werror):

src/libstrongswan/plugins/fips_prf/fips_prf.c:124:12: error: array subscript 18446744073709551615 is above array bounds of ‘uint8_t[<U8090>]’ {aka ‘unsigned char[<U8090>]’} [-Werror=array-bounds]
  124 |         one[this->b - 1] = 0x01;
      |         ~~~^~~~~~~~~~~~~

src/libstrongswan/plugins/fips_prf/fips_prf.c

index a51cfe105ffaffe24e396632bbfcb189f55953f4..3acec596e2cb278ac827126f7be296887c1e355e 100644 (file)
@@ -114,9 +114,9 @@ METHOD(prf_t, get_bytes, bool,
        uint8_t *xkey = this->key;
        uint8_t one[this->b];
 
-       if (!w)
+       if (!w || !this->b)
        {
-               /* append mode is not supported */
+               /* append mode is not supported, the other check is to make GCC happy */
                return FALSE;
        }