Skip to content

Commit

Permalink
further snprintf hardening
Browse files Browse the repository at this point in the history
  • Loading branch information
ep69 committed Mar 8, 2024
1 parent 08b7df0 commit 1287699
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/crypt-pbkdf1-sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ crypt_sha1crypt_rn (const char *phrase, size_t phr_size,
}

sl = (size_t)(sp - setting);
assert (sl <= CRYPT_SHA1_SALT_LENGTH);

/*
* Now get to work...
* Prime the pump with <salt><magic><iterations>
*/
dl = snprintf ((char *)output, out_size, "%.*s%s%lu",
(int)sl, setting, magic, iterations);
assert (dl > 0);
/*
* Then hmac using <phrase> as key, and repeat...
*/
Expand Down
1 change: 1 addition & 0 deletions lib/crypt-sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions lib/crypt-sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 1287699

Please sign in to comment.