瀏覽代碼

modules/auth Fixed a bug when realm is NULL in challenge method

Marius Zbihlei 14 年之前
父節點
當前提交
1c9ccc1237
共有 1 個文件被更改,包括 14 次插入6 次删除
  1. 14 6
      modules/auth/challenge.c

+ 14 - 6
modules/auth/challenge.c

@@ -124,9 +124,13 @@ int get_challenge_hf(struct sip_msg* msg, int stale, str* realm,
     nonce_len = get_nonce_len(cfg, nc_enabled || otn_enabled);
 
     hf.len = hfn->len;
-    hf.len += DIGEST_REALM_LEN
-	+ realm->len
-	+ DIGEST_NONCE_LEN;
+    if (realm) {
+		hf.len += DIGEST_REALM_LEN
+		+ realm->len; 
+    }
+
+    hf.len += DIGEST_NONCE_LEN;
+
     if (nonce) {
     	hf.len += nonce->len
     	          + 1; /* '"' */
@@ -156,10 +160,14 @@ int get_challenge_hf(struct sip_msg* msg, int stale, str* realm,
 		ERR("auth: No memory left (%d bytes)\n", hf.len);
 		return -1;
     }
-    
+
     memcpy(p, hfn->s, hfn->len); p += hfn->len;
-    memcpy(p, DIGEST_REALM, DIGEST_REALM_LEN); p += DIGEST_REALM_LEN;
-    memcpy(p, realm->s, realm->len); p += realm->len;
+
+    if(realm){
+	memcpy(p, DIGEST_REALM, DIGEST_REALM_LEN); p += DIGEST_REALM_LEN;
+	memcpy(p, realm->s, realm->len); p += realm->len;
+    }
+
     memcpy(p, DIGEST_NONCE, DIGEST_NONCE_LEN); p += DIGEST_NONCE_LEN;
     if (nonce) {
         memcpy(p, nonce->s, nonce->len); p += nonce->len;