From b9cab65e320fccc04cd06694e717db5e4abb5dcc Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sat, 24 Apr 2004 23:57:22 +0000 Subject: Put nice assertions all over the place. --- daemon/digest.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'daemon/digest.c') diff --git a/daemon/digest.c b/daemon/digest.c index 51120a0..79b4ff3 100644 --- a/daemon/digest.c +++ b/daemon/digest.c @@ -22,6 +22,7 @@ void digest_makenonce(unsigned char* nonce, unsigned char* secret, unsigned char internal_nonce_t in; md5_ctx_t md5; + ASSERT(nonce && secret); ASSERT(sizeof(internal_nonce_t) == DIGEST_NONCE_LEN); if(old) @@ -51,6 +52,7 @@ int digest_checknonce(unsigned char* nonce, unsigned char* secret, time_t* tm) { internal_nonce_t in; + ASSERT(nonce && secret); ASSERT(sizeof(internal_nonce_t) == DIGEST_NONCE_LEN); digest_makenonce((unsigned char*)&in, secret, nonce); @@ -69,6 +71,9 @@ int digest_checknonce(unsigned char* nonce, unsigned char* secret, time_t* tm) digest_record_t* digest_makerec(unsigned char* nonce, const char* user) { digest_record_t* rec = (digest_record_t*)malloc(sizeof(*rec)); + + ASSERT(nonce && user); + if(!rec) { ha_messagex(LOG_CRIT, "out of memory"); @@ -85,8 +90,7 @@ digest_record_t* digest_makerec(unsigned char* nonce, const char* user) const char* digest_challenge(ha_buffer_t* buf, unsigned char* nonce, const char* realm, const char* domains, int stale) { - ASSERT(realm); - ASSERT(nonce); + ASSERT(buf && realm && nonce); ha_bufmcat(buf, HA_PREFIX_DIGEST, " realm=\"", realm, "\", nonce=\"", NULL); ha_bufjoin(buf); @@ -128,15 +132,12 @@ const char* digest_challenge(ha_buffer_t* buf, unsigned char* nonce, int digest_parse(char* header, ha_buffer_t* buf, digest_header_t* rec, unsigned char* nonce) { - /* - * This function destroys the contents of header by - * terminating strings in it all over the place. - */ - char next; char* key; char* value; + ASSERT(header && buf && rec); + header = ha_bufcpy(buf, header); if(!header) @@ -258,6 +259,10 @@ int digest_check(const char* realm, const char* method, const char* uri, const char* digest; const char* t; + ASSERT(realm && method && uri && buf && dg && rec); + + /* TODO: Many of these should somehow communicate BAD REQ back to the client */ + /* Check for digest */ if(!dg->digest || !dg->digest[0]) { @@ -448,6 +453,8 @@ const char* digest_respond(ha_buffer_t* buf, digest_header_t* dg, const char* nextnonce = NULL; const char* t; + ASSERT(buf && dg && rec); + if(next) { nextnonce = ha_bufenc64(buf, next, DIGEST_NONCE_LEN); @@ -523,6 +530,9 @@ void digest_makeha1(unsigned char* digest, const char* user, const char* realm, const char* password) { md5_ctx_t md5; + + ASSERT(digest && user && realm && password); + md5_init(&md5); md5_update(&md5, user, strlen(user)); md5_update(&md5, ":", 1); @@ -530,4 +540,4 @@ void digest_makeha1(unsigned char* digest, const char* user, md5_update(&md5, ":", 1); md5_update(&md5, password, strlen(password)); md5_final(digest, &md5); -} \ No newline at end of file +} -- cgit v1.2.3