Browse Source

dialplan: use size_t to get the size of compiled pcre

- it caused crash on 64b since size was declared as int and
  pcre_fullinfo() expects size_t (on 32b is the same struct size)
- reported by Javier Gallart and Bayan Towfiq
- credits to Bayan for provinding testing environment and
  troubleshooting assistance, closes FS#109
(cherry picked from commit 12aebbf1056a3b51e349de6e69e2aca1801905a3)
Daniel-Constantin Mierla 14 years ago
parent
commit
d2729211fc
1 changed files with 33 additions and 32 deletions
  1. 33 32
      modules/dialplan/dp_db.c

+ 33 - 32
modules/dialplan/dp_db.c

@@ -303,39 +303,40 @@ int str_to_shm(str src, str * dest)
 /* Compile pcre pattern and return pointer to shm copy of result */
 static pcre *reg_ex_comp(const char *pattern, int *cap_cnt)
 {
-    pcre *re, *result;
-    const char *error;
-    int rc, size, err_offset;
-
-    re = pcre_compile(pattern, 0, &error, &err_offset, NULL);
-    if (re == NULL) {
-	LM_ERR("PCRE compilation of '%s' failed at offset %d: %s\n",
-	       pattern, err_offset, error);
-	return (pcre *)0;
-    }
-    rc = pcre_fullinfo(re, NULL, PCRE_INFO_SIZE, &size);
-    if (rc != 0) {
-	pcre_free(re);
-	LM_ERR("pcre_fullinfo on compiled pattern '%s' yielded error: %d\n",
-	       pattern, rc);
-	return (pcre *)0;
-    }
-    rc = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, cap_cnt);
-    if (rc != 0) {
-	pcre_free(re);
-	LM_ERR("pcre_fullinfo on compiled pattern '%s' yielded error: %d\n",
-	       pattern, rc);
-	return (pcre *)0;
-    }
-    result = (pcre *)shm_malloc(size);
-    if (result == NULL) {
+	pcre *re, *result;
+	const char *error;
+	int rc, err_offset;
+	size_t size;
+
+	re = pcre_compile(pattern, 0, &error, &err_offset, NULL);
+	if (re == NULL) {
+		LM_ERR("PCRE compilation of '%s' failed at offset %d: %s\n",
+			pattern, err_offset, error);
+		return (pcre *)0;
+	}
+	rc = pcre_fullinfo(re, NULL, PCRE_INFO_SIZE, &size);
+	if (rc != 0) {
+		pcre_free(re);
+		LM_ERR("pcre_fullinfo on compiled pattern '%s' yielded error: %d\n",
+			pattern, rc);
+		return (pcre *)0;
+	}
+	rc = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, cap_cnt);
+	if (rc != 0) {
+		pcre_free(re);
+		LM_ERR("pcre_fullinfo on compiled pattern '%s' yielded error: %d\n",
+			pattern, rc);
+		return (pcre *)0;
+	}
+	result = (pcre *)shm_malloc(size);
+	if (result == NULL) {
+		pcre_free(re);
+		LM_ERR("not enough shared memory for compiled PCRE pattern\n");
+		return (pcre *)0;
+	}
+	memcpy(result, re, size);
 	pcre_free(re);
-	LM_ERR("not enough shared memory for compiled PCRE pattern\n");
-	return (pcre *)0;
-    }
-    memcpy(result, re, size);
-    pcre_free(re);
-    return result;
+	return result;
 }