]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
creds-util: fix possible divide-by-zero
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 18 Aug 2021 07:05:02 +0000 (16:05 +0900)
committerLennart Poettering <lennart@poettering.net>
Thu, 19 Aug 2021 07:49:00 +0000 (09:49 +0200)
input_size may be zero.

Fixes #20469.

src/shared/creds-util.c

index 3bc5fbef51268b3e379f471c4015a451a5bb5ec1..9980cd93a92b47b83abab0b4e559b80e93d2c92c 100644 (file)
@@ -667,11 +667,11 @@ int encrypt_credential_and_warn(
         p += tsz;
         assert(p <= output_size);
 
-        if (DEBUG_LOGGING) {
+        if (DEBUG_LOGGING && input_size > 0) {
                 size_t base64_size;
 
                 base64_size = DIV_ROUND_UP(p * 4, 3); /* Include base64 size increase in debug output */
-
+                assert(base64_size >= input_size);
                 log_debug("Input of %zu bytes grew to output of %zu bytes (+%2zu%%).", input_size, base64_size, base64_size * 100 / input_size - 100);
         }