Re: Re[2]: SMSBox PANIC

Alexander Malysh <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Organization Centrium GmbH
Message-ID <[email protected]>
Hi Jury,

please try attached patch. 

Note: this patch is not as complete to treat, it's just a few points for a way 
how to fix things. I can only say to all: smsbox is grown with time and is 
now the big, ugly _mess_! 

On Saturday 13 December 2003 16:28, Jury Cherepanov wrote:
> Hello Alexander,
>
> Saturday, December 13, 2003, 5:20:47 PM, you wrote:
>
> AM> Hi,
>
> AM> would you please recode stackframes to addresses as follow:
> AM> addr2line -e path_to_this_smsbox_binary 0x806bea6 0x80707f2 0x806cd8f \
> AM> 0x8051744 0x806497b
>
> AM> or Tip: recompile with '--with-cflags="-rdynamic"'.
>
> AM> Thanks in advance...
>
> AM> On Saturday 13 December 2003 15:53, Jury Cherepanov wrote:
> >> Hello devel,
> >>
> >>   Log:
> >>
> >> cc:/usr/local/wapgw/sbin# tail -f sbox.log
>
> AM> [snip]
>
> >> (text)> 2003-12-13 16:49:10 [3] DEBUG: Status: 403 Answer:
> >> <Authorization failed for sendsms> 2003-12-13 16:49:10 [3] PANIC:
> >> gwlib/octstr.c:2238: seems_valid_real: Assertion `ostr->len + 1 <=
> >> ostr->size' failed. (Called from gwlib/octstr.c:304:octstr_destroy.)
> >> 2003-12-13 16:49:10 [3] PANIC: ./smsbox [0x806bea6]
> >> 2003-12-13 16:49:10 [3] PANIC: ./smsbox [0x80707f2]
> >> 2003-12-13 16:49:10 [3] PANIC: ./smsbox [0x806cd8f]
> >> 2003-12-13 16:49:10 [3] PANIC: ./smsbox [0x8051744]
> >> 2003-12-13 16:49:10 [3] PANIC: ./smsbox [0x806497b]
> >> 2003-12-13 16:49:10 [3] PANIC: /lib/libpthread.so.0 [0x4009c10c]
> >> 2003-12-13 16:49:10 [3] PANIC: /lib/libc.so.6(__clone+0x3a) [0x4027083a]
> >>
> >>
> >>
> >> ---------------------------------------------------------
> >> Jury Cherepanov
> >> System Developer (Technical Director) , HIGH TECHNOLOGIES
> >> Turaidas 2a, Riga, Latvia
> >> Phone +371-6451718
> >> mailto:[email protected]
>
> /tmp/kannel-snapshot/gwlib/log.c:540
> /tmp/kannel-snapshot/gwlib/octstr.c:2239
> /tmp/kannel-snapshot/gwlib/octstr.c:306
> /tmp/kannel-snapshot/gw/smsbox.c:2993
> /tmp/kannel-snapshot/gwlib/gwthread-pthread.c:343
>
> ---------------------------------------------------------
> Jury Cherepanov
> System Developer (Technical Director) , HIGH TECHNOLOGIES
> Turaidas 2a, Riga, Latvia
> Phone +371-6451718
> mailto:[email protected]

-- 
Best regards / Mit besten Grüßen aus Düsseldorf

Dipl.-Ing.
Alexander Malysh
___________________________________________

Centrium GmbH
Vogelsanger Weg 80
40470 Düsseldorf

Fon: +49 (0211) 74 84 51 80
Fax: +49 (0211) 277 49 109

email: a.malysh at centrium.de
web: www.centrium.de
msn: olek2002 at hotmail.com
icq: 98063111
___________________________________________

Please avoid sending me Word, Excel or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
smsbox-start-of-fixing.diff (text/x-diff, 12.3 KB)
Index: gw/smsbox.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsbox.c,v
retrieving revision 1.240
diff -a -u -r1.240 smsbox.c
--- gw/smsbox.c	8 Dec 2003 11:25:44 -0000	1.240
+++ gw/smsbox.c	15 Dec 2003 21:28:41 -0000
@@ -560,9 +560,9 @@
 /* requesttype = mt_reply or mt_push. for example, auth is only read on mt_push
  * parse body and populate fields, including replacing body for <ud> value and
  * type to text/plain */
-static void get_x_kannel_from_xml(int requesttype , Octstr **type, Octstr **body, 
+static void get_x_kannel_from_xml(int requesttype , const Octstr *type, const Octstr *body, 
                                   List *headers, Octstr **from,
-                                  Octstr **to, Octstr **udh,
+                                  Octstr **to, Octstr **text, Octstr **udh,
                                   Octstr **user, Octstr **pass,
                                   Octstr **smsc, int *mclass, int *mwi,
                                   int *coding, int *compress,
@@ -573,15 +573,15 @@
                                   Octstr **binfo)
 {                                    
 
-    Octstr *text, *tmp, *tmp2;
+    Octstr *tmp, *tmp2;
     long tmplong, where;
     
-    tmp = tmp2 = text = NULL;
+    tmp = tmp2 = NULL;
 
-    debug("sms", 0, "XMLParsing: XML: <%s>", octstr_get_cstr(*body));
+    debug("sms", 0, "XMLParsing: XML: <%s>", octstr_get_cstr(body));
 
     /* auth */
-    get_tag(*body, octstr_imm("from"), &tmp, 0, 0);
+    get_tag(body, octstr_imm("from"), &tmp, 0, 0);
     if(tmp) {
 	if(requesttype == mt_push) {
 	    /* user */
@@ -605,7 +605,7 @@
     if(requesttype == mt_push) {
 	/* to (da/number) Multiple tags */ 
 	*tolist = list_create();
-	where = get_tag(*body, octstr_imm("da"), &tmp, 0, 0);
+	where = get_tag(body, octstr_imm("da"), &tmp, 0, 0);
 	if(tmp) {
 	    get_tag(tmp, octstr_imm("number"), to, 0, 0);
 	    list_append(*tolist, octstr_duplicate(*to));
@@ -613,7 +613,7 @@
 
 	    while(tmp && where != -1) {
 		O_DESTROY(tmp);
-		where = get_tag(*body, octstr_imm("da"), &tmp, where, 0);
+		where = get_tag(body, octstr_imm("da"), &tmp, where, 0);
 		if(tmp) {
 		    get_tag(tmp, octstr_imm("number"), &tmp2, 0, 0);
 		    if(tmp2 != NULL) {
@@ -626,7 +626,7 @@
     }
 
     /* udh */
-    get_tag(*body, octstr_imm("udh"), &tmp, 0, 0);
+    get_tag(body, octstr_imm("udh"), &tmp, 0, 0);
     if(tmp) {
 	O_DESTROY(*udh);
 	*udh = octstr_duplicate(tmp);
@@ -636,14 +636,14 @@
     }
 
     /* smsc */
-    get_tag(*body, octstr_imm("to"), &tmp, 0, 0);
+    get_tag(body, octstr_imm("to"), &tmp, 0, 0);
     if(tmp) {
 	get_tag(tmp, octstr_imm("account"), smsc, 0, 0);
 	O_DESTROY(tmp);
     }
 
     /* pid */
-    get_tag(*body, octstr_imm("pid"), &tmp, 0, 0);
+    get_tag(body, octstr_imm("pid"), &tmp, 0, 0);
     if(tmp) {
 	if(octstr_parse_long(&tmplong, tmp, 0, 10) != -1)
 	    *pid = tmplong;
@@ -651,7 +651,7 @@
     }
 
     /* rpi */
-    get_tag(*body, octstr_imm("rpi"), &tmp, 0, 0);
+    get_tag(body, octstr_imm("rpi"), &tmp, 0, 0);
     if(tmp) {
 	if(octstr_parse_long(&tmplong, tmp, 0, 10) != -1)
 	    *rpi = tmplong;
@@ -659,7 +659,7 @@
     }
 
     /* dcs* (dcs/ *) */
-    get_tag(*body, octstr_imm("dcs"), &tmp, 0, 0);
+    get_tag(body, octstr_imm("dcs"), &tmp, 0, 0);
     if(tmp) {
 	/* mclass (dcs/mclass) */
 	get_tag(tmp, octstr_imm("mclass"), &tmp2, 0, 0);
@@ -700,7 +700,7 @@
     }
 
     /* statusrequest* (statusrequest/ *) */
-    get_tag(*body, octstr_imm("statusrequest"), &tmp, 0, 0);
+    get_tag(body, octstr_imm("statusrequest"), &tmp, 0, 0);
     if(tmp) {
 	/* dlr-mask (statusrequest/dlr-mask) */
 	get_tag(tmp, octstr_imm("dlr-mask"), &tmp2, 0, 0);
@@ -714,7 +714,7 @@
     }
 
     /* validity (vp/delay) */
-    get_tag(*body, octstr_imm("vp"), &tmp, 0, 0);
+    get_tag(body, octstr_imm("vp"), &tmp, 0, 0);
     if(tmp) {
 	get_tag(tmp, octstr_imm("delay"), &tmp2, 0, 0);
 	if(tmp2) {
@@ -726,7 +726,7 @@
     }
 
     /* deferred (timing/delay) */
-    get_tag(*body, octstr_imm("timing"), &tmp, 0, 0);
+    get_tag(body, octstr_imm("timing"), &tmp, 0, 0);
     if(tmp) {
 	get_tag(tmp, octstr_imm("delay"), &tmp2, 0, 0);
 	if(tmp2) {
@@ -738,7 +738,7 @@
     }
 
     /* charset from <?xml...encoding=?> */
-    tmp = find_charset_encoding(*body);
+    tmp = find_charset_encoding(body);
     O_DESTROY(*charset);
     if(tmp) {
 	*charset = octstr_duplicate(tmp);
@@ -748,24 +748,14 @@
     }
 
     /* text */
-    text = NULL;
-    get_tag(*body, octstr_imm("ud"), &tmp, 0, 0);
+    get_tag(body, octstr_imm("ud"), &tmp, 0, 0);
     if(tmp) {
-	O_DESTROY(text);
-	text = octstr_duplicate(tmp);
-	if(octstr_hex_to_binary(text) == -1)
-	    octstr_url_decode(text);
-	O_DESTROY(tmp);
+	*text = tmp;
+	if(octstr_hex_to_binary(*text) == -1)
+	    octstr_url_decode(*text);
     }
-
-    O_DESTROY(*body);
-    if(text)
-	*body = text;
     else
-	*body = octstr_create("");
-
-    O_DESTROY(*type);
-    *type = octstr_create("text/plain");
+	*text = octstr_create("");
 }
 
 
@@ -1021,9 +1011,9 @@
             break;
 
 	octets = 0;
-    from = to = udh = smsc = dlr_url = account = binfo = charset = NULL;
+        from = to = udh = smsc = dlr_url = account = binfo = charset = NULL;
 	mclass = mwi = coding = compress = pid = alt_dcs = rpi = dlr_mask 
-        = validity = deferred = -1;
+            = validity = deferred = -1;
 
         get_receiver(id, &msg, &trans, &method, &req_url, &req_headers, &req_body, &retries);
 
@@ -1044,8 +1034,6 @@
 					  &binfo);
             } else if (octstr_case_compare(type, text_plain) == 0) {
                 replytext = octstr_duplicate(reply_body);
-                octstr_destroy(reply_body);
-                reply_body = NULL;
                 get_x_kannel_from_headers(reply_headers, &from, &to, &udh,
 					  NULL, NULL, &smsc, &mclass, &mwi,
 					  &coding, &compress, &validity,
@@ -1053,17 +1041,13 @@
 					  &account, &pid, &alt_dcs, &rpi,
 					  &binfo);
             } else if (octstr_case_compare(type, text_xml) == 0) {
-                replytext = octstr_duplicate(reply_body);
-                octstr_destroy(reply_body);
-                reply_body = NULL;
-                get_x_kannel_from_xml(mt_reply, &type, &replytext, reply_headers,
-                        &from, &to, &udh, NULL, NULL, &smsc, &mclass, &mwi,
+                get_x_kannel_from_xml(mt_reply, type, reply_body, reply_headers,
+                        &from, &to, &replytext, &udh, NULL, NULL, &smsc, &mclass, &mwi,
                         &coding, &compress, &validity, &deferred, &dlr_mask,
                         &dlr_url, &account, &pid, &alt_dcs, &rpi, NULL, &charset,
                         &binfo);
             } else if (octstr_case_compare(type, octet_stream) == 0) {
                 replytext = octstr_duplicate(reply_body);
-                octstr_destroy(reply_body);
                 octets = 1;
                 reply_body = NULL;
                 get_x_kannel_from_headers(reply_headers, &from, &to, &udh,
@@ -2394,58 +2378,51 @@
  * Create and send an SMS message from an HTTP request.
  * Args: args contains the CGI parameters
  */
-static Octstr *smsbox_sendsms_post(List *headers, Octstr *body,
-				   Octstr *client_ip, int *status)
+static Octstr *smsbox_sendsms_post(const List *headers, const Octstr *body,
+				   const Octstr *client_ip, int *status)
 {
     URLTranslation *t = NULL;
     Octstr *user, *pass, *ret, *type;
     List *tolist;
-    Octstr *text_html, *text_plain, *text_wml, *text_xml, *octet_stream;
     Octstr *text;
     Octstr *from, *to, *udh, *smsc, *charset, *dlr_url, *account, *binfo;
     int dlr_mask, mclass, mwi, coding, compress, validity, deferred;
     int pid, alt_dcs, rpi;
  
-    text_html = octstr_imm("text/html");
-    text_wml = octstr_imm("text/vnd.wap.wml");
-    text_plain = octstr_imm("text/plain");
-    text_xml = octstr_imm("text/xml");
-    octet_stream = octstr_imm("application/octet-stream");
-
     user = pass = ret = type = NULL;
     tolist = NULL;
-    from = to = udh = smsc = account = dlr_url = charset = binfo = NULL;
+    from = to = udh = text = smsc = account = dlr_url = charset = binfo = NULL;
     mclass = mwi = coding = compress = validity = deferred = dlr_mask = 
-        pid = alt_dcs = rpi = -1;
+        pid = alt_dcs = rpi = SMS_PARAM_UNDEFINED;
  
     http_header_get_content_type(headers, &type, &charset);
-    if (octstr_case_compare(type, text_html) == 0 ||
-	octstr_case_compare(type, text_wml) == 0) {
+    if (octstr_case_compare(type, octstr_imm("text/html")) == 0 ||
+	octstr_case_compare(type, octstr_imm("text/vnd.wap.wml")) == 0) {
 	text = html_to_sms(body);
 	octstr_strip_blanks(text);
-	octstr_destroy(body);
-	body = text;
 	get_x_kannel_from_headers(headers, &from, &to, &udh,
 				  &user, &pass, &smsc, &mclass, &mwi, 
 				  &coding, &compress, &validity, 
 				  &deferred, &dlr_mask, &dlr_url, 
 				  &account, &pid, &alt_dcs, &rpi,
 				  &binfo);
-    } else if (octstr_case_compare(type, text_plain) == 0 ||
-               octstr_case_compare(type, octet_stream) == 0) {
+    } else if (octstr_case_compare(type, octstr_imm("text/plain")) == 0 ||
+               octstr_case_compare(type, octstr_imm("application/octet-stream")) == 0) {
 	get_x_kannel_from_headers(headers, &from, &to, &udh,
 				  &user, &pass, &smsc, &mclass, &mwi, 
 				  &coding, &compress, &validity, 
 				  &deferred, &dlr_mask, &dlr_url, 
 				  &account, &pid, &alt_dcs, &rpi,
 				  &binfo);
-    } else if (octstr_case_compare(type, text_xml) == 0) {
-	get_x_kannel_from_xml(mt_push, &type, &body, headers, 
-                              &from, &to, &udh, &user, &pass, &smsc, &mclass, 
+    } else if (octstr_case_compare(type, octstr_imm("text/xml")) == 0) {
+	get_x_kannel_from_xml(mt_push, type, body, headers, 
+                              &from, &to, &text, &udh, &user, &pass, &smsc, &mclass, 
 			      &mwi, &coding, &compress, &validity, &deferred,
 			      &dlr_mask, &dlr_url, &account, &pid, &alt_dcs,
 			      &rpi, &tolist, &charset, &binfo);
     } else {
+        error(0, "%s got weird content type %s", octstr_get_cstr(sendsms_url),
+		  octstr_get_cstr(type));
 	*status = HTTP_BAD_REQUEST;
 	ret = octstr_create("Invalid content-type");
 	goto error;
@@ -2454,7 +2431,7 @@
     if (charset_processing(charset, body, coding) == -1) {
 	*status = HTTP_BAD_REQUEST;
 	ret = octstr_create("Invalid charset");
-	goto error2;
+	goto error;
     }
 
     /* check the username and password */
@@ -2471,43 +2448,36 @@
     else if (to != NULL && octstr_len(to) == 0) {
 	error(0, "%s got empty <to> cgi variable", octstr_get_cstr(sendsms_url));
 	*status = HTTP_BAD_REQUEST;
-	return octstr_create("Empty receiver number not allowed, rejected");
+	ret = octstr_create("Empty receiver number not allowed, rejected");
     } 
     else {
-	if (octstr_case_compare(type,
-				octstr_imm("application/octet-stream")) == 0) {
-	    if (coding == DC_UNDEF)
-		coding = DC_8BIT; /* XXX Force UCS2 with DC Field */
-	} else if (octstr_case_compare(type,
-				       octstr_imm("text/plain")) == 0) {
-	    if (coding == DC_UNDEF)
-		coding = DC_7BIT;
-	} else {
-	    error(0, "%s got weird content type %s", octstr_get_cstr(sendsms_url),
-		  octstr_get_cstr(type));
-	    *status = HTTP_UNSUPPORTED_MEDIA_TYPE;
-	    ret = octstr_create("Unsupported content-type, rejected");
-	}
-
-	if (ret == NULL)
-	    ret = smsbox_req_handle(t, client_ip, from, to, body, charset,
+	if (octstr_case_compare(type, octstr_imm("application/octet-stream")) == 0 && coding == DC_UNDEF)
+            coding = DC_8BIT; /* XXX Force UCS2 with DC Field */
+	else if (coding == DC_UNDEF)
+            coding = DC_7BIT;
+
+	/* XXX memleak here , tolist will be destroyed in smsbox_req_handle but not if error occurs */
+	if (ret == NULL) {
+	    ret = smsbox_req_handle(t, client_ip, from, to, text, charset,
 				    udh, smsc, mclass, mwi, coding, compress, 
 				    validity, deferred, status, dlr_mask, 
 				    dlr_url, account, pid, alt_dcs, rpi, tolist,
 				    binfo);
-
+	}
     }
-error2:
+
+error:
+    list_destroy(tolist, octstr_destroy_item);
     octstr_destroy(user);
     octstr_destroy(pass);
     octstr_destroy(from);
     octstr_destroy(to);
+    octstr_destroy(text);
     octstr_destroy(udh);
     octstr_destroy(smsc);
     octstr_destroy(dlr_url);
     octstr_destroy(account);
     octstr_destroy(binfo);
-error:
     octstr_destroy(type);
     octstr_destroy(charset);
     return ret;
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQA/3ihAnX3e5W+uJ0ERAnzQAJ9s4WaoAai2WC0uI9R1bU4bIl/2oQCfV8AR
8tK5FSrTr6fL1Wn4wx1motM=
=hNdB
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.