Module: sip-router
Branch: kamailio_3.0
Commit: d2729211fc9c50acf13f11ce533687164fea0458
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d272921…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sun Jan 2 16:00:13 2011 +0100
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)
---
modules/dialplan/dp_db.c | 65 +++++++++++++++++++++++----------------------
1 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/modules/dialplan/dp_db.c b/modules/dialplan/dp_db.c
index 262e552..97c07ba 100644
--- a/modules/dialplan/dp_db.c
+++ b/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;
}