Patch to avoid panic of opensmppbox and add EXPIRE status

Денис Давыдов <[email protected]> Fri, 24 Nov 2017 14:03:57 +0300
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <CAA5Vwz_R8h12V_j=vSy6hSUb4FK0DocoQuiyGmO04k2rDb441Q@mail.gmail.com>
Hi,

I had crashed the opensmppbox when I've used smsc-route group to route MT
messages out of the box. For example, if you add such block to route MT
from esme test1 to the smsc jasper you'll get panic:

group = smsc-route
smsbox-id = test1
smsc-id = jasper

2017-11-16 10:36:32 [1578] [0] INFO: Starting to log to file
/var/log/kannel/opensmppbox.log level 0
2017-11-16 10:36:32 [1578] [0] INFO: Added logfile
`/var/log/kannel/opensmppbox.log' with level `0'.
2017-11-16 10:36:32 [1578] [0] DEBUG: Adding smsc routing to id <jasper>
for box id <test1>
2017-11-16 10:36:32 [1578] [0] PANIC: gwlib/octstr.c:2564:
seems_valid_real: Assertion `ostr->data != NULL' failed. (Called from
gwlib/octstr.c:325:octstr_destroy.)
2017-11-16 10:36:32 [1578] [0] PANIC:
/usr/local/kannel/sbin/opensmppbox(gw_backtrace+0xae) [0x45654e]
2017-11-16 10:36:32 [1578] [0] PANIC:
/usr/local/kannel/sbin/opensmppbox(gw_panic+0x15f) [0x4566bf]
2017-11-16 10:36:32 [1578] [0] PANIC: /usr/local/kannel/sbin/opensmppbox()
[0x45dac0]
2017-11-16 10:36:32 [1578] [0] PANIC:
/usr/local/kannel/sbin/opensmppbox(octstr_destroy+0x1d) [0x45dfbd]
2017-11-16 10:36:32 [1578] [0] PANIC:
/usr/local/kannel/sbin/opensmppbox(main+0x8bc) [0x40bf6c]
2017-11-16 10:36:32 [1578] [0] PANIC:
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7ffff5e7cc05]
2017-11-16 10:36:32 [1578] [0] PANIC: /usr/local/kannel/sbin/opensmppbox()
[0x40c82a]

There's an issue of freeing of unallocated pointers. This has been fixed.

Another issue found in delivery receipt with EXPIRE status that coming from
smsc to esme with "stat:(null)" status instead of EXPIRED. I have added the
EXPIRE status in msg_to_pdu of opensmppbox. In some cases it's very
important to get this status instead of "(null)" value in delivery receipt.

See attached patch. Please share any feedback.

Thank you.

--
Regards,
Denis S.Davydov
opensmppbox.c.patch (application/octet-stream, 1.1 KB)
--- addons/opensmppbox/gw/opensmppbox.c	2017-11-24 12:12:11.783382183 +0300
+++ addons/opensmppbox/gw/opensmppbox.c	2017-11-24 12:10:11.229445024 +0300
@@ -843,6 +843,9 @@
 		dlr_status = octstr_imm("DELIVRD");
 		dlvrd = octstr_imm("001");
 		break;
+        case DLR_EXPIRED:
+                dlr_state = 3;
+                dlr_status = octstr_imm("EXPIRED");
 	case DLR_BUFFERED:
 		dlr_state = 6;
 		dlr_status = octstr_imm("ACCEPTD");
@@ -2324,6 +2327,7 @@
                           octstr_get_cstr(item));
             }
             gwlist_destroy(items, octstr_destroy_item);
+            octstr_destroy(receiver_shortcodes);
         };
 
         /* consider now the 3 possibilities: */
@@ -2388,11 +2392,10 @@
                 gwlist_destroy(subitems, octstr_destroy_item);
             }
             gwlist_destroy(items, octstr_destroy_item);
+            octstr_destroy(boxc_ids);
             octstr_destroy(shortcodes);
         }
         octstr_destroy(smsc_id);
-        octstr_destroy(boxc_ids);
-        octstr_destroy(shortcodes);
     }
 
     gwlist_destroy(list, NULL);