diff --git a/lib/crypt-pbkdf1-sha1.c b/lib/crypt-pbkdf1-sha1.c index 5e320d04..2727899e 100644 --- a/lib/crypt-pbkdf1-sha1.c +++ b/lib/crypt-pbkdf1-sha1.c @@ -155,6 +155,7 @@ crypt_sha1crypt_rn (const char *phrase, size_t phr_size, */ dl = snprintf ((char *)output, out_size, "%.*s%s%lu", (int)sl, setting, magic, iterations); + assert (dl > 0); /* * Then hmac using as key, and repeat... */ @@ -165,8 +166,10 @@ crypt_sha1crypt_rn (const char *phrase, size_t phr_size, hmac_sha1_process_data (hmac_buf, SHA1_SIZE, pwu, pl, hmac_buf); } /* Now output... */ - pl = (size_t)snprintf ((char *)output, out_size, "%s%lu$%.*s$", - magic, iterations, (int)sl, setting); + dl = snprintf ((char *)output, out_size, "%s%lu$%.*s$", + magic, iterations, (int)sl, setting); + assert (dl > 0); + pl = (size_t) dl; ep = output + pl; /* Every 3 bytes of hash gives 24 bits which is 4 base64 chars */ diff --git a/lib/crypt-sha256.c b/lib/crypt-sha256.c index 6d21fa3c..9b32df52 100644 --- a/lib/crypt-sha256.c +++ b/lib/crypt-sha256.c @@ -261,6 +261,7 @@ crypt_sha256crypt_rn (const char *phrase, size_t phr_size, int n = snprintf (cp, SHA256_HASH_LENGTH - (sizeof (sha256_salt_prefix) - 1), "%s%zu$", sha256_rounds_prefix, rounds); + assert (n > 0); cp += n; } diff --git a/lib/crypt-sha512.c b/lib/crypt-sha512.c index 59ae9708..11aa0116 100644 --- a/lib/crypt-sha512.c +++ b/lib/crypt-sha512.c @@ -265,6 +265,7 @@ crypt_sha512crypt_rn (const char *phrase, size_t phr_size, int n = snprintf (cp, SHA512_HASH_LENGTH - (sizeof (sha512_salt_prefix) - 1), "%s%zu$", sha512_rounds_prefix, rounds); + assert (n > 0); cp += n; } diff --git a/lib/crypt-sunmd5.c b/lib/crypt-sunmd5.c index 9a871db5..26faccd7 100644 --- a/lib/crypt-sunmd5.c +++ b/lib/crypt-sunmd5.c @@ -300,8 +300,9 @@ gensalt_sunmd5_rn (unsigned long count, assert (count != 0); - size_t written = (size_t) snprintf ((char *)output, o_size, - "%s,rounds=%lu$", SUNMD5_PREFIX, count); + int written = snprintf ((char *)output, o_size, + "%s,rounds=%lu$", SUNMD5_PREFIX, count); + assert (written > 0); write_itoa64_4(output + written + 0, rbytes[2], rbytes[3], rbytes[4]); diff --git a/lib/util-gensalt-sha.c b/lib/util-gensalt-sha.c index 4c6cf780..e7c141a5 100644 --- a/lib/util-gensalt-sha.c +++ b/lib/util-gensalt-sha.c @@ -60,8 +60,12 @@ gensalt_sha_rn (char tag, size_t maxsalt, unsigned long defcount, written = 3; } else - written = (size_t) snprintf ((char *)output, output_size, - "$%c$rounds=%lu$", tag, count); + { + int w = snprintf ((char *)output, output_size, + "$%c$rounds=%lu$", tag, count); + assert (w > 0); + written = (size_t) w; + } /* The length calculation above should ensure that this is always true. */ assert (written + 5 < output_size);