Parcourir la source

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 il y a 10 ans
Parent
commit
89642d3cdd
1 fichiers modifiés avec 2 ajouts et 1 suppressions
  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.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) {
 	if (np->src_ip.s == NULL) {
 		LM_CRIT("cannot allocate shm memory for src_ip string\n");
 		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);
 	(void) strncpy(np->src_ip.s, src_ip, np->src_ip.len);
+	np->src_ip.s[np->src_ip.len] = 0;
 
 
 	if (pattern) {
 	if (pattern) {
 		np->pattern = (char *) shm_malloc(strlen(pattern)+1);
 		np->pattern = (char *) shm_malloc(strlen(pattern)+1);