Explorar el Código

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

Jan Janak hace 22 años
padre
commit
97a94ea7c2
Se han modificado 2 ficheros con 10 adiciones y 2 borrados
  1. 9 1
      parser/digest/digest.c
  2. 1 1
      parser/digest/digest_parser.c

+ 9 - 1
parser/digest/digest.c

@@ -44,7 +44,7 @@ static inline int new_credentials(struct hdr_field* _h)
 	b = (auth_body_t*)pkg_malloc(sizeof(auth_body_t));
 	if (b == 0) {
 		LOG(L_ERR, "parse_credentials(): No memory left\n");
-		return -2;
+		return -1;
 	}
 		
 	init_dig_cred(&(b->digest));
@@ -60,6 +60,10 @@ static inline int new_credentials(struct hdr_field* _h)
 
 /*
  * Parse digest credentials
+ * Return value -1 means that the function was unable to allocate
+ * memory and therefore the server should return Internal Server Error,
+ * not Bad Request in this case !
+ * Bad Request should be send when return value != -1
  */
 int parse_credentials(struct hdr_field* _h)
 {
@@ -74,6 +78,10 @@ int parse_credentials(struct hdr_field* _h)
 		return -1;
 	}
 
+	     /* parse_digest_cred must return < -1 on error otherwise we will be
+	      * unable to distinguis if the error was caused by the server or if the
+	      * credentials are broken
+	      */
 	res = parse_digest_cred(&(_h->body), &(((auth_body_t*)(_h->parsed))->digest));
 	
 	if (res != 0) {

+ 1 - 1
parser/digest/digest_parser.c

@@ -344,7 +344,7 @@ int parse_digest_cred(str* _s, dig_cred_t* _c)
 
 		     /* And parse digest parameters */
 		if (parse_digest_params(&tmp, _c) < 0) {
-			return -1;
+			return -2; /* We must not return -1 in this function ! */
 		} else {
 			return 0;
 		}