diff options
author | William Roberts <william.c.roberts@intel.com> | 2018-12-10 11:47:35 -0800 |
---|---|---|
committer | Tadeusz Struk <tadeusz.struk@intel.com> | 2018-12-13 15:40:11 -0800 |
commit | 675fe7e0108a7fc772d1fd7729449e4474242214 (patch) | |
tree | 6ba3e33f579b970ffb96cc344064975dabcb4ec6 /test | |
parent | ceb7cbc3ab339b1577d220d7fc184660e0a0d2ee (diff) | |
download | tpm2-tss-675fe7e0108a7fc772d1fd7729449e4474242214.tar.gz |
test: fix overflow warning
gcc with -Wstrict-overflow=5 produces the following error:
../test/integration/sapi-session-util.c: In function ‘gen_session_key.part.0.constprop.1’:
../test/integration/sapi-session-util.c:580:40: error: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C1 +- C2 [-Werror=strict-overflow]
if (iv->size > sizeof (iv->buffer) ||
^
cc1: all warnings being treated as errors
This is due to type promotion of addition where anything smaller than int (UINT16) is promoted to int, which is
signed addition and thus can have a signed overflow issue.
Signed-off-by: William Roberts <william.c.roberts@intel.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/sapi-session-util.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/test/integration/sapi-session-util.c b/test/integration/sapi-session-util.c index a1b61140..3ae6ad89 100644 --- a/test/integration/sapi-session-util.c +++ b/test/integration/sapi-session-util.c @@ -577,8 +577,9 @@ gen_session_key( iv->size = aes_block_size; session_key->size = (session->symmetric.keyBits.sym) / 8; + UINT16 total_size = session_key->size + iv->size; if (iv->size > sizeof (iv->buffer) || - (session_key->size + iv->size) > TPM2_MAX_DIGEST_BUFFER) + (total_size) > TPM2_MAX_DIGEST_BUFFER) return TSS2_SYS_RC_GENERAL_FAILURE; memcpy (iv->buffer, &key.buffer[session_key->size], iv->size); |