浏览代码

permissions: store src ip in zero terminated string for trusted table

- it is printed as string via rpc, resulting in invalid chars in the
  output
- reported by Emmanuel Schmidbauer, GH#137
Daniel-Constantin Mierla 10 年之前
父节点
当前提交
89642d3cdd
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      modules/permissions/hash.c

+ 2 - 1
modules/permissions/hash.c

@@ -155,7 +155,7 @@ int hash_table_insert(struct trusted_list** table, char* src_ip,
 	}
 
 	np->src_ip.len = strlen(src_ip);
-	np->src_ip.s = (char *) shm_malloc(np->src_ip.len);
+	np->src_ip.s = (char *) shm_malloc(np->src_ip.len+1);
 
 	if (np->src_ip.s == NULL) {
 		LM_CRIT("cannot allocate shm memory for src_ip string\n");
@@ -164,6 +164,7 @@ int hash_table_insert(struct trusted_list** table, char* src_ip,
 	}
 
 	(void) strncpy(np->src_ip.s, src_ip, np->src_ip.len);
+	np->src_ip.s[np->src_ip.len] = 0;
 
 	if (pattern) {
 		np->pattern = (char *) shm_malloc(strlen(pattern)+1);