浏览代码

auth_xkeys: clone value before inserting the lump inside auth_xkeys_add()

Daniel-Constantin Mierla 6 年之前
父节点
当前提交
01f5ecbc45
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. 10 1
      src/modules/auth_xkeys/auth_xkeys.c

+ 10 - 1
src/modules/auth_xkeys/auth_xkeys.c

@@ -202,6 +202,7 @@ int auth_xkeys_add(sip_msg_t* msg, str *hdr, str *key,
 	auth_xkey_t *itc;
 	auth_xkey_t *itc;
 	char xout[SHA512_DIGEST_STRING_LENGTH];
 	char xout[SHA512_DIGEST_STRING_LENGTH];
 	struct lump* anchor;
 	struct lump* anchor;
+	char *p;
 
 
 	if(_auth_xkeys_list==NULL || *_auth_xkeys_list==NULL) {
 	if(_auth_xkeys_list==NULL || *_auth_xkeys_list==NULL) {
 		LM_ERR("no stored keys\n");
 		LM_ERR("no stored keys\n");
@@ -266,8 +267,16 @@ int auth_xkeys_add(sip_msg_t* msg, str *hdr, str *key,
 		LM_ERR("can't get anchor\n");
 		LM_ERR("can't get anchor\n");
 		return -1;
 		return -1;
 	}
 	}
-	if (insert_new_lump_before(anchor, xdata.s, xdata.len, 0) == 0) {
+	p = (char*)pkg_malloc(xdata.len+1);
+	if(p==NULL) {
+		LM_ERR("no more pkg memory\n");
+		return -2;
+	}
+	memcpy(p, xdata.s, xdata.len);
+	p[xdata.len] = '\0';
+	if (insert_new_lump_before(anchor, p, xdata.len, 0) == 0) {
 		LM_ERR("cannot insert the new header [%.*s]\n", hdr->len, hdr->s);
 		LM_ERR("cannot insert the new header [%.*s]\n", hdr->len, hdr->s);
+		pkg_free(p);
 		return -1;
 		return -1;
 	}
 	}
 	return 0;
 	return 0;