Ver código fonte

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

Daniel-Constantin Mierla 6 anos atrás
pai
commit
01f5ecbc45
1 arquivos alterados com 10 adições e 1 exclusões
  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;
 	char xout[SHA512_DIGEST_STRING_LENGTH];
 	struct lump* anchor;
+	char *p;
 
 	if(_auth_xkeys_list==NULL || *_auth_xkeys_list==NULL) {
 		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");
 		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);
+		pkg_free(p);
 		return -1;
 	}
 	return 0;