Module: kamailio
Branch: 5.2
Commit: 28b00bd2a8cb0e894475ff78fdd45cca40f63a08
URL:
https://github.com/kamailio/kamailio/commit/28b00bd2a8cb0e894475ff78fdd45cc…
Author: Henning Westerholt <hw(a)kamailio.org>
Committer: Henning Westerholt <hw(a)kamailio.org>
Date: 2019-02-07T21:30:48+01:00
core: fix crashes and logical errors for cmd line parsing, reported from Thuan Pham
- fix a bunch of crashes and logical errors for command line parsing
- do not parse tcp, tls and sctp in listen statement if TCP or SCTP is disabled
- this will later crash during module startup (e.g. in tm)
- do not allow to config TCP and SCTP children count if TCP or SCTP is disabled
- report error messages in this cases to help users detect it
- reported from Thuan Pham, Thuan.Pham at monash dot edu
(cherry picked from commit f0290969fdcbbeede62091a649597c23617571a9)
---
Modified: src/main.c
---
Diff:
https://github.com/kamailio/kamailio/commit/28b00bd2a8cb0e894475ff78fdd45cc…
Patch:
https://github.com/kamailio/kamailio/commit/28b00bd2a8cb0e894475ff78fdd45cc…
---
diff --git a/src/main.c b/src/main.c
index 31ab2d6161..99fa60ba34 100644
--- a/src/main.c
+++ b/src/main.c
@@ -952,10 +952,16 @@ int parse_proto(unsigned char* s, long len, int* proto)
break;
#ifdef USE_TCP
case PROTO2UINT3('t', 'c', 'p'):
+ if (tcp_disable) {
+ return -1;
+ }
*proto=PROTO_TCP;
break;
#ifdef USE_TLS
case PROTO2UINT3('t', 'l', 's'):
+ if (tcp_disable || tls_disable) {
+ return -1;
+ }
*proto=PROTO_TLS;
break;
#endif
@@ -967,10 +973,14 @@ int parse_proto(unsigned char* s, long len, int* proto)
#ifdef USE_SCTP
else if (likely(len==4)){
i=PROTO2UINT4(s[0], s[1], s[2], s[3]);
- if (i==PROTO2UINT4('s', 'c', 't', 'p'))
+ if (i==PROTO2UINT4('s', 'c', 't', 'p')) {
+ if (sctp_disable) {
+ return -1;
+ }
*proto=PROTO_SCTP;
- else
+ } else {
return -1;
+ }
}
#endif /* USE_SCTP */
else
@@ -2218,10 +2228,25 @@ int main(int argc, char** argv)
goto error;
}
break;
+ case 'T':
+ #ifdef USE_TCP
+ tcp_disable=1;
+ #else
+ fprintf(stderr,"WARNING: tcp support not compiled in\n");
+ #endif
+ break;
+ case 'S':
+ #ifdef USE_SCTP
+ sctp_disable=1;
+ #else
+ fprintf(stderr,"WARNING: sctp support not compiled in\n");
+ #endif
+ break;
case 'l':
if ((n_lst=parse_phostport_mh(optarg, &tmp, &tmp_len,
&port, &proto))==0){
- fprintf(stderr, "bad -l address specifier: %s\n",
+ fprintf(stderr, "bad -l address specifier: %s\n"
+ "Check disabled protocols\n",
optarg);
goto error;
}
@@ -2254,15 +2279,13 @@ int main(int argc, char** argv)
case 'D':
dont_fork_cnt++;
break;
- case 'T':
- #ifdef USE_TCP
- tcp_disable=1;
- #else
- fprintf(stderr,"WARNING: tcp support not compiled in\n");
- #endif
- break;
case 'N':
#ifdef USE_TCP
+ if (tcp_disable) {
+ fprintf(stderr, "could not configure TCP children: -N %s\n"
+ "TCP support disabled\n", optarg);
+ goto error;
+ }
tcp_cfg_children_no=strtol(optarg, &tmp, 10);
if ((tmp==0) ||(*tmp)){
fprintf(stderr, "bad process number: -N %s\n",
@@ -2285,15 +2308,13 @@ int main(int argc, char** argv)
fprintf(stderr,"WARNING: tcp support not compiled in\n");
#endif
break;
- case 'S':
- #ifdef USE_SCTP
- sctp_disable=1;
- #else
- fprintf(stderr,"WARNING: sctp support not compiled in\n");
- #endif
- break;
case 'Q':
#ifdef USE_SCTP
+ if (sctp_disable) {
+ fprintf(stderr, "could not configure SCTP children: -Q %s\n"
+ "SCTP support disabled\n", optarg);
+ goto error;
+ }
sctp_children_no=strtol(optarg, &tmp, 10);
if ((tmp==0) ||(*tmp)){
fprintf(stderr, "bad process number: -O %s\n",