From de883c68b2443b7b5f9f3bd290d004dec58956b2 Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Thu, 2 Jun 2005 12:46:36 +0000 Subject: [PATCH] fixed crash in mm7soap proxy --- mbuni/mmlib/mms_mm7soap.h | 1 + mbuni/mmsc/mmsproxy.c | 68 +++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/mbuni/mmlib/mms_mm7soap.h b/mbuni/mmlib/mms_mm7soap.h index 74a5bed..981da87 100644 --- a/mbuni/mmlib/mms_mm7soap.h +++ b/mbuni/mmlib/mms_mm7soap.h @@ -4,6 +4,7 @@ #define MM7_SOAP_OK 1000 #define MM7_SOAP_FORMAT_CORRUPT 2007 +#define MM7_SOAP_UNSUPPORTED_OPERATION 4003 #define MM7_SOAP_STATUS_OK(e) ((e) / 1000 == 1) #define MM7_DEFAULT_VERSION "5.3.0" diff --git a/mbuni/mmsc/mmsproxy.c b/mbuni/mmsc/mmsproxy.c index e691013..c153ca9 100644 --- a/mbuni/mmsc/mmsproxy.c +++ b/mbuni/mmsc/mmsproxy.c @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) Octstr *log, *alog; long loglevel; - MmsHTTPClientInfo h; + MmsHTTPClientInfo h = {NULL}; long mm7_thread = -1; @@ -141,8 +141,9 @@ int main(int argc, char *argv[]) MmsHTTPClientInfo *hx = gw_malloc(sizeof *hx); Octstr *profile_url; - memset(hx, 0, sizeof *hx); - + + h.vasp = NULL; + h.prof = NULL; h.ua = http_header_value(h.headers, octstr_imm("User-Agent")); /* Get the profile URL and store it. Has effect of fetching if missing. */ @@ -158,9 +159,10 @@ int main(int argc, char *argv[]) h.prof = mms_make_ua_profile(h.headers); /* Get the sender address. */ - - - h.base_client_addr = mms_find_sender_msisdn(h.url, h.headers, settings->wap_gw_msisdn_header, settings->mms_detokenizefuncs); + h.base_client_addr = mms_find_sender_msisdn(h.url, + h.headers, + settings->wap_gw_msisdn_header, + settings->mms_detokenizefuncs); if (!h.base_client_addr) { /* Set to IP sender... XXXX assumes ipv4 only for now*/ if (settings->allow_ip_type) { @@ -169,7 +171,8 @@ int main(int argc, char *argv[]) settings->wap_gw_ip_header, h.ip, &ipv6); h.client_addr = octstr_format("%S/TYPE=IPv%s", - h.base_client_addr, ipv6 ? "6" : "4"); + h.base_client_addr, + ipv6 ? "6" : "4"); } else h.client_addr = NULL; @@ -1628,10 +1631,9 @@ static void mm7soap_dispatch(MmsHTTPClientInfo *h) " --> Enterred mm7dispatch interface, mreq=%s mtype = %s <-- ", mreq ? "Ok" : "Null", mreq ? (char *)msgtype : "Null"); - - + if (!mreq) { - mresp = mm7_make_resp(NULL, 2007, NULL); + mresp = mm7_make_resp(NULL, MM7_SOAP_FORMAT_CORRUPT, NULL); goto done; } @@ -1765,15 +1767,22 @@ static void mm7soap_dispatch(MmsHTTPClientInfo *h) mresp = mm7_make_resp(mreq, status, NULL); break; default: - + mresp = mm7_make_resp(mreq, MM7_SOAP_UNSUPPORTED_OPERATION, NULL); break; } done: + + if (mresp && mm7_soapmsg_to_httpmsg(mresp, &rh, &reply_body) == 0) http_send_reply(h->client, hstatus, rh, reply_body); else http_close_client(h->client); + + debug("mmsprox.mm7sendinterface", 0, + " --> leaving mm7dispatch interface, mresp=%s, body=%s <-- ", + mresp ? "ok" : "(null)", + reply_body ? "ok" : "(null)"); if (e) mms_queue_free_env(e); @@ -1944,7 +1953,7 @@ static void mm7eaif_dispatch(MmsHTTPClientInfo *h) static void mm7proxy(void *unused) { - MmsHTTPClientInfo h; + MmsHTTPClientInfo h = {NULL}; while(rstop == 0 && (h.client = http_accept_request(settings->mm7port, &h.ip, &h.url, &h.headers, @@ -1952,10 +1961,13 @@ static void mm7proxy(void *unused) if (is_allowed_ip(settings->deny_ip, settings->allow_ip, h.ip)) { MmsHTTPClientInfo *hx = gw_malloc(sizeof *hx); - memset(hx, 0, sizeof *hx); - /* Get the MM7 sender address. */ - + /* Clear some stuff. */ + h.client_addr = NULL; + h.base_client_addr = NULL; + h.prof = NULL; + + /* Get the MM7 sender address. */ h.vasp = find_mm7sender(h.headers, settings->vasp_list); h.ua = http_header_value(h.headers, octstr_imm("User-Agent")); debug("mmsproxy", 0, @@ -1992,21 +2004,37 @@ static void mm7proxy(void *unused) static void free_clientInfo(MmsHTTPClientInfo *h, int freeh) { + + debug("free info", 0, + " entered free_clientinfo %d, ip=%d", freeh, (int)h->ip); + if (h->ip) octstr_destroy(h->ip); + + if (h->url) octstr_destroy(h->url); if (h->ua) octstr_destroy(h->ua); + + if (h->body) octstr_destroy(h->body); + if (h->base_client_addr) octstr_destroy(h->base_client_addr); - if (h->client_addr) - octstr_destroy(h->client_addr); - http_destroy_cgiargs(h->cgivars); - http_destroy_headers(h->headers); + if (h->client_addr) + octstr_destroy(h->client_addr); + + if (h->cgivars) + http_destroy_cgiargs(h->cgivars); + + if (h->headers) + http_destroy_headers(h->headers); if (freeh) - gw_free(h); + gw_free(h); + + debug("free info", 0, + " left free_clientinfo"); }