Module: sip-router Branch: master Commit: 12aebbf1056a3b51e349de6e69e2aca1801905a3 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=12aebbf1...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@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
---
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 62a64e4..155b2a0 100644 --- a/modules/dialplan/dp_db.c +++ b/modules/dialplan/dp_db.c @@ -316,39 +316,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; }