[w3m-dev 04131] Hash of entity body (was Re: Multiple challeges in *-Authenticate header)

Kiyokazu SUTO <[email protected]> 18 Dec 2004 20:20:02 +0900
Newsgroups gmane.comp.web.w3m.devel
Message-ID <[email protected]>
[w3m-dev 04130]request->body


# [w3m-dev 04130]fuzz
# 

-- 
  <[email protected]>
http://pub.ks-and-ks.ne.jp/pgp-public-key.html

-----  -----  -----  -----  -----
--- file.c~	Sat Dec 18 14:08:35 2004
+++ file.c	Sat Dec 18 20:13:03 2004
@@ -1267,19 +1267,27 @@
     tmp = Strnew_m_charp(HTTPrequestMethod(hr)->ptr, ":", uri->ptr, NULL);
     if (qop && (strcasecmp(qop->ptr, "auth-int") == 0)) {
 	/*  A2 = Method ":" digest-uri-value ":" H(entity-body) */
-	Str ebody = Strnew();
 	if (request && request->body) {
-	    FILE *fp = fopen(request->body, "r");
-	    if (fp != NULL) {
-		int c;
-		while ((c = fgetc(fp)) != EOF)
-		    Strcat_char(ebody, c);
-		fclose(fp);
+	    if (request->enctype == FORM_ENCTYPE_MULTIPART) {
+		FILE *fp = fopen(request->body, "r");
+		if (fp != NULL) {
+		    Str ebody;
+		    ebody = Strfgetall(fp);
+		    MD5(ebody->ptr, strlen(ebody->ptr), md5);
+		}
+		else {
+		    MD5("", 0, md5);
+		}
 	    }
+	    else {
+		MD5(request->body, request->length, md5);
+	    }
+	}
+	else {
+	    MD5("", 0, md5);
 	}
-	MD5(ebody->ptr, strlen(ebody->ptr), md5);
-	ebody = digest_hex(md5);
-	Strcat_m_charp(tmp, ":", ebody->ptr, NULL);
+	Strcat_char(tmp, ':');
+	Strcat(tmp, digest_hex(md5));
     }
     MD5(tmp->ptr, strlen(tmp->ptr), md5);
     a2buf = digest_hex(md5);