From 46394bd631ee051753e91d57e9c537413dd360a6 Mon Sep 17 00:00:00 2001 From: Justin W Smith <103147162+justsmth@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:44:36 -0400 Subject: [PATCH] Quell static-analysis concern about div-by-0 (#1866) ### Issues: Addresses #1856 ### Description of changes: Clarify pkcs8 logic so it doesn't trip up static analysis. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license. --- crypto/pkcs8/pkcs8.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crypto/pkcs8/pkcs8.c b/crypto/pkcs8/pkcs8.c index 4bc337bfd6..9cea6471c4 100644 --- a/crypto/pkcs8/pkcs8.c +++ b/crypto/pkcs8/pkcs8.c @@ -167,8 +167,11 @@ int pkcs12_key_gen(const char *pass, size_t pass_len, const uint8_t *salt, for (size_t i = 0; i < S_len; i++) { I[i] = salt[i % salt_len]; } - for (size_t i = 0; i < P_len; i++) { - I[i + S_len] = pass_raw[i % pass_raw_len]; + // P_len would be 0 in this case, but static analyzers don't always see that + if(pass_raw_len > 0) { + for (size_t i = 0; i < P_len; i++) { + I[i + S_len] = pass_raw[i % pass_raw_len]; + } } while (out_len != 0) {