diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-04-30 19:39:33 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-04-30 19:39:33 +0300 |
commit | bf9ca17361a998b27c7f091af7b0ab6966c995e0 (patch) | |
tree | f48426b5b5013776230cbcc084a4ebd2a3b2a60d /src/microhttpd/digestauth.c | |
parent | 0effaaad3ef06ce2fad2dd493d3064c259b3fe52 (diff) | |
download | libmicrohttpd-bf9ca17361a998b27c7f091af7b0ab6966c995e0.tar.gz libmicrohttpd-bf9ca17361a998b27c7f091af7b0ab6966c995e0.zip |
check_nonce_nc(): use already known nonce size, avoid size recalculation
Diffstat (limited to 'src/microhttpd/digestauth.c')
-rw-r--r-- | src/microhttpd/digestauth.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c index 25cae280..232d0e23 100644 --- a/src/microhttpd/digestauth.c +++ b/src/microhttpd/digestauth.c | |||
@@ -537,24 +537,25 @@ fast_simple_hash (const uint8_t *data, | |||
537 | * | 537 | * |
538 | * @param connection The MHD connection structure | 538 | * @param connection The MHD connection structure |
539 | * @param nonce A pointer that referenced a zero-terminated array of nonce | 539 | * @param nonce A pointer that referenced a zero-terminated array of nonce |
540 | * @param noncelen the lenth of @a nonce, in characters | ||
540 | * @param nc The nonce counter, zero to add the nonce to the array | 541 | * @param nc The nonce counter, zero to add the nonce to the array |
541 | * @return #MHD_YES if successful, #MHD_NO if invalid (or we have no NC array) | 542 | * @return #MHD_YES if successful, #MHD_NO if invalid (or we have no NC array) |
542 | */ | 543 | */ |
543 | static enum MHD_Result | 544 | static enum MHD_Result |
544 | check_nonce_nc (struct MHD_Connection *connection, | 545 | check_nonce_nc (struct MHD_Connection *connection, |
545 | const char *nonce, | 546 | const char *nonce, |
547 | size_t noncelen, | ||
546 | uint64_t nc) | 548 | uint64_t nc) |
547 | { | 549 | { |
548 | struct MHD_Daemon *daemon = connection->daemon; | 550 | struct MHD_Daemon *daemon = connection->daemon; |
549 | struct MHD_NonceNc *nn; | 551 | struct MHD_NonceNc *nn; |
550 | uint32_t off; | 552 | uint32_t off; |
551 | uint32_t mod; | 553 | uint32_t mod; |
552 | size_t noncelen; | ||
553 | enum MHD_Result ret; | 554 | enum MHD_Result ret; |
554 | bool stale; | 555 | bool stale; |
555 | 556 | ||
556 | stale = false; | 557 | stale = false; |
557 | noncelen = strlen (nonce) + 1; | 558 | mhd_assert (noncelen != strlen (nonce)); |
558 | if (MAX_NONCE_LENGTH < noncelen) | 559 | if (MAX_NONCE_LENGTH < noncelen) |
559 | return MHD_NO; /* This should be impossible, but static analysis | 560 | return MHD_NO; /* This should be impossible, but static analysis |
560 | tools have a hard time with it *and* this also | 561 | tools have a hard time with it *and* this also |
@@ -578,7 +579,7 @@ check_nonce_nc (struct MHD_Connection *connection, | |||
578 | /* Fresh nonce, reinitialize array */ | 579 | /* Fresh nonce, reinitialize array */ |
579 | memcpy (nn->nonce, | 580 | memcpy (nn->nonce, |
580 | nonce, | 581 | nonce, |
581 | noncelen); | 582 | noncelen + 1); |
582 | nn->nc = 0; | 583 | nn->nc = 0; |
583 | nn->nmask = 0; | 584 | nn->nmask = 0; |
584 | ret = MHD_YES; | 585 | ret = MHD_YES; |
@@ -872,6 +873,7 @@ digest_auth_check_all (struct MHD_Connection *connection, | |||
872 | size_t len; | 873 | size_t len; |
873 | const char *header; | 874 | const char *header; |
874 | char nonce[MAX_NONCE_LENGTH]; | 875 | char nonce[MAX_NONCE_LENGTH]; |
876 | size_t nonce_len; | ||
875 | char cnonce[MAX_NONCE_LENGTH]; | 877 | char cnonce[MAX_NONCE_LENGTH]; |
876 | const unsigned int digest_size = da->digest_size; | 878 | const unsigned int digest_size = da->digest_size; |
877 | char ha1[VLA_ARRAY_LEN_DIGEST (digest_size) * 2 + 1]; | 879 | char ha1[VLA_ARRAY_LEN_DIGEST (digest_size) * 2 + 1]; |
@@ -935,6 +937,7 @@ digest_auth_check_all (struct MHD_Connection *connection, | |||
935 | header, | 937 | header, |
936 | "nonce"))) | 938 | "nonce"))) |
937 | return MHD_NO; | 939 | return MHD_NO; |
940 | nonce_len = len; | ||
938 | left -= strlen ("nonce") + len; | 941 | left -= strlen ("nonce") + len; |
939 | if (left > 32 * 1024) | 942 | if (left > 32 * 1024) |
940 | { | 943 | { |
@@ -1047,6 +1050,7 @@ digest_auth_check_all (struct MHD_Connection *connection, | |||
1047 | if (MHD_NO == | 1050 | if (MHD_NO == |
1048 | check_nonce_nc (connection, | 1051 | check_nonce_nc (connection, |
1049 | nonce, | 1052 | nonce, |
1053 | nonce_len, | ||
1050 | nci)) | 1054 | nci)) |
1051 | { | 1055 | { |
1052 | return MHD_NO; | 1056 | return MHD_NO; |
@@ -1394,6 +1398,7 @@ MHD_queue_auth_fail_response2 (struct MHD_Connection *connection, | |||
1394 | if (MHD_NO == | 1398 | if (MHD_NO == |
1395 | check_nonce_nc (connection, | 1399 | check_nonce_nc (connection, |
1396 | nonce, | 1400 | nonce, |
1401 | NONCE_STD_LEN (da.digest_size), | ||
1397 | 0)) | 1402 | 0)) |
1398 | { | 1403 | { |
1399 | #ifdef HAVE_MESSAGES | 1404 | #ifdef HAVE_MESSAGES |