[sr-dev] git:master:f0290969: core: fix crashes and logical errors for cmd line parsing, reported from Thuan Pham
Henning Westerholt
hw at kamailio.org
Thu Feb 7 21:30:09 CET 2019
Module: kamailio
Branch: master
Commit: f0290969fdcbbeede62091a649597c23617571a9
URL: https://github.com/kamailio/kamailio/commit/f0290969fdcbbeede62091a649597c23617571a9
Author: Henning Westerholt <hw at kamailio.org>
Committer: Henning Westerholt <hw at kamailio.org>
Date: 2019-02-07T21:26:27+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
---
Modified: src/main.c
---
Diff: https://github.com/kamailio/kamailio/commit/f0290969fdcbbeede62091a649597c23617571a9.diff
Patch: https://github.com/kamailio/kamailio/commit/f0290969fdcbbeede62091a649597c23617571a9.patch
---
diff --git a/src/main.c b/src/main.c
index 4e3b9112e4..d052ee4e97 100644
--- a/src/main.c
+++ b/src/main.c
@@ -954,10 +954,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
@@ -969,10 +975,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
@@ -2261,10 +2271,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;
}
@@ -2297,15 +2322,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",
@@ -2328,15 +2351,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",
More information about the sr-dev
mailing list