do not abort on nonce slot collisions with different algorithms

This commit is contained in:
Christian Grothoff
2026-07-28 10:55:44 +02:00
parent 3b898eaea7
commit f438804c18
+21 -8
View File
@@ -857,19 +857,32 @@ check_nonce_nc (struct MHD_Connection *connection,
MHD_mutex_lock_chk_ (&daemon->nnc_lock);
mhd_assert (0 == nn->nonce[noncelen]); /* The old value must be valid */
if ( (0 != memcmp (nn->nonce, nonce, noncelen)) ||
(0 != nn->nonce[noncelen]) )
{ /* The nonce in the slot does not match nonce from the client */
/* The nonces recorded in the array do not all have the same length: the
* daemon may serve several digest algorithms at the same time and the
* length of the nonce depends on the size of the digest (44 characters
* for MD5, 76 for SHA-256 and SHA-512/256). The slot selected by the
* hash of the client's nonce may therefore hold a nonce of a completely
* different length, which must not be inspected with the client's
* length. */
if (strlen (nn->nonce) != noncelen)
{
if (0 == nn->nonce[0])
{ /* The slot was never used, while the client's nonce value should be
* recorded when it was generated by MHD */
ret = MHD_CHECK_NONCENC_WRONG;
}
else if (0 != nn->nonce[noncelen])
{ /* The value is the slot is wrong */
ret = MHD_CHECK_NONCENC_STALE;
else
{ /* The slot holds a nonce generated for another digest algorithm.
* The client's nonce is not (or no longer) recorded. */
ret = MHD_CHECK_NONCENC_STALE;
}
}
else if (0 != memcmp (nn->nonce, nonce, noncelen))
{ /* The nonce in the slot does not match nonce from the client */
if (0 == nn->nonce[0])
{ /* The slot was never used, while the client's nonce value should be
* recorded when it was generated by MHD */
ret = MHD_CHECK_NONCENC_WRONG;
}
else
{