Browse code

Changed return value of parse_digest a bit, it is possible to distinguish if the the parser failed because of memory.

Jan Janak authored on 25/01/2003 15:13:02
Showing 2 changed files
... ...
@@ -44,7 +44,7 @@ static inline int new_credentials(struct hdr_field* _h)
44 44
 	b = (auth_body_t*)pkg_malloc(sizeof(auth_body_t));
45 45
 	if (b == 0) {
46 46
 		LOG(L_ERR, "parse_credentials(): No memory left\n");
47
-		return -2;
47
+		return -1;
48 48
 	}
49 49
 		
50 50
 	init_dig_cred(&(b->digest));
... ...
@@ -60,6 +60,10 @@ static inline int new_credentials(struct hdr_field* _h)
60 60
 
61 61
 /*
62 62
  * Parse digest credentials
63
+ * Return value -1 means that the function was unable to allocate
64
+ * memory and therefore the server should return Internal Server Error,
65
+ * not Bad Request in this case !
66
+ * Bad Request should be send when return value != -1
63 67
  */
64 68
 int parse_credentials(struct hdr_field* _h)
65 69
 {
... ...
@@ -74,6 +78,10 @@ int parse_credentials(struct hdr_field* _h)
74 78
 		return -1;
75 79
 	}
76 80
 
81
+	     /* parse_digest_cred must return < -1 on error otherwise we will be
82
+	      * unable to distinguis if the error was caused by the server or if the
83
+	      * credentials are broken
84
+	      */
77 85
 	res = parse_digest_cred(&(_h->body), &(((auth_body_t*)(_h->parsed))->digest));
78 86
 	
79 87
 	if (res != 0) {
... ...
@@ -344,7 +344,7 @@ int parse_digest_cred(str* _s, dig_cred_t* _c)
344 344
 
345 345
 		     /* And parse digest parameters */
346 346
 		if (parse_digest_params(&tmp, _c) < 0) {
347
-			return -1;
347
+			return -2; /* We must not return -1 in this function ! */
348 348
 		} else {
349 349
 			return 0;
350 350
 		}