Browse code

rtpengine: fix issues reported by Coverity

Richard Fuchs authored on 27/07/2017 14:23:32
Showing 1 changed files
... ...
@@ -568,7 +568,10 @@ static int bind_force_send_ip(int sock_idx)
568 568
 			memset(&ip4addr, 0, sizeof(ip4addr));
569 569
 			ip4addr.sin_family = AF_INET;
570 570
 			ip4addr.sin_port = htons(0);
571
-			inet_pton(AF_INET, force_send_ip_str, &ip4addr.sin_addr);
571
+			if (inet_pton(AF_INET, force_send_ip_str, &ip4addr.sin_addr) != 1) {
572
+				LM_ERR("failed to parse IPv4 address %s\n", force_send_ip_str);
573
+				return -1;
574
+			}
572 575
 
573 576
 			if (bind(rtpp_socks[sock_idx], (struct sockaddr*)&ip4addr, sizeof(ip4addr)) < 0) {
574 577
 				LM_ERR("can't bind socket to required ipv4 interface\n");
... ...
@@ -576,9 +579,12 @@ static int bind_force_send_ip(int sock_idx)
576 579
 			}
577 580
 
578 581
 			memset(&tmp, 0, sizeof(tmp));
579
-			getsockname(rtpp_socks[sock_idx], (struct sockaddr *) &tmp, &sock_len);
580
-			inet_ntop(AF_INET, &tmp.sin_addr, str_addr, INET_ADDRSTRLEN);
581
-			LM_DBG("Binding on %s:%d\n", str_addr, ntohs(tmp.sin_port));
582
+			if (getsockname(rtpp_socks[sock_idx], (struct sockaddr *) &tmp, &sock_len))
583
+				LM_ERR("could not determine local socket name\n");
584
+			else {
585
+				inet_ntop(AF_INET, &tmp.sin_addr, str_addr, INET_ADDRSTRLEN);
586
+				LM_DBG("Binding on %s:%d\n", str_addr, ntohs(tmp.sin_port));
587
+			}
582 588
 
583 589
 			break;
584 590
 
... ...
@@ -591,7 +597,10 @@ static int bind_force_send_ip(int sock_idx)
591 597
 			ip6addr.sin6_family = AF_INET6;
592 598
 			ip6addr.sin6_port = htons(0);
593 599
 			ip6addr.sin6_scope_id = scope;
594
-			inet_pton(AF_INET6, force_send_ip_str, &ip6addr.sin6_addr);
600
+			if (inet_pton(AF_INET6, force_send_ip_str, &ip6addr.sin6_addr) != 1) {
601
+				LM_ERR("failed to parse IPv6 address %s\n", force_send_ip_str);
602
+				return -1;
603
+			}
595 604
 
596 605
 			if ((ret = bind(rtpp_socks[sock_idx], (struct sockaddr*)&ip6addr, sizeof(ip6addr))) < 0) {
597 606
 				LM_ERR("can't bind socket to required ipv6 interface\n");
... ...
@@ -600,9 +609,12 @@ static int bind_force_send_ip(int sock_idx)
600 609
 			}
601 610
 
602 611
 			memset(&tmp6, 0, sizeof(tmp6));
603
-			getsockname(rtpp_socks[sock_idx], (struct sockaddr *) &tmp6, &sock_len);
604
-			inet_ntop(AF_INET6, &tmp6.sin6_addr, str_addr6, INET6_ADDRSTRLEN);
605
-			LM_DBG("Binding on ipv6 %s:%d\n", str_addr6, ntohs(tmp6.sin6_port));
612
+			if (getsockname(rtpp_socks[sock_idx], (struct sockaddr *) &tmp6, &sock_len))
613
+				LM_ERR("could not determine local socket name\n");
614
+			else {
615
+				inet_ntop(AF_INET6, &tmp6.sin6_addr, str_addr6, INET6_ADDRSTRLEN);
616
+				LM_DBG("Binding on ipv6 %s:%d\n", str_addr6, ntohs(tmp6.sin6_port));
617
+			}
606 618
 
607 619
 			break;
608 620
 
... ...
@@ -710,11 +722,13 @@ struct rtpp_set *get_rtpp_set(unsigned int set_id)
710 722
 	unsigned int my_current_id = 0;
711 723
 	int new_list;
712 724
 
725
+#if DEFAULT_RTPP_SET_ID > 0
713 726
 	if (set_id < DEFAULT_RTPP_SET_ID )
714 727
 	{
715 728
 		LM_ERR(" invalid rtpproxy set value [%u]\n", set_id);
716 729
 		return NULL;
717 730
 	}
731
+#endif
718 732
 
719 733
 	my_current_id = set_id;
720 734
 	/*search for the current_id*/
... ...
@@ -1037,6 +1051,7 @@ static int fixup_set_id(void ** param, int param_no)
1037 1051
 		rtpl->rpv = pv_cache_get(&s);
1038 1052
 		if(rtpl->rpv == NULL) {
1039 1053
 			LM_ERR("invalid pv parameter %s\n", s.s);
1054
+			pkg_free(rtpl);
1040 1055
 			return -1;
1041 1056
 		}
1042 1057
 	} else {
... ...
@@ -1045,11 +1060,13 @@ static int fixup_set_id(void ** param, int param_no)
1045 1060
 			pkg_free(*param);
1046 1061
 			if((rtpp_list = select_rtpp_set(set_id)) ==0){
1047 1062
 				LM_ERR("rtpp_proxy set %u not configured\n", set_id);
1063
+				pkg_free(rtpl);
1048 1064
 				return E_CFG;
1049 1065
 			}
1050 1066
 			rtpl->rset = rtpp_list;
1051 1067
 		} else {
1052 1068
 			LM_ERR("bad number <%s>\n",	(char *)(*param));
1069
+			pkg_free(rtpl);
1053 1070
 			return E_CFG;
1054 1071
 		}
1055 1072
 	}
... ...
@@ -1651,9 +1668,10 @@ static int build_rtpp_socks() {
1651 1668
 			}
1652 1669
 
1653 1670
 #ifdef IP_MTU_DISCOVER
1654
-			setsockopt(rtpp_socks[pnode->idx], IPPROTO_IP,
1655
-				IP_MTU_DISCOVER, &ip_mtu_discover,
1656
-				sizeof(ip_mtu_discover));
1671
+			if (setsockopt(rtpp_socks[pnode->idx], IPPROTO_IP,
1672
+					IP_MTU_DISCOVER, &ip_mtu_discover,
1673
+					sizeof(ip_mtu_discover)))
1674
+				LM_WARN("Failed enable set MTU discovery socket option\n");
1657 1675
 #endif
1658 1676
 
1659 1677
 			if (bind_force_send_ip(pnode->idx) == -1) {
... ...
@@ -2455,6 +2473,7 @@ send_rtpp_command(struct rtpp_node *node, bencode_item_t *dict, int *outlen)
2455 2473
 		/* Drain input buffer */
2456 2474
 		while ((poll(fds, 1, 0) == 1) &&
2457 2475
 			((fds[0].revents & POLLIN) != 0)) {
2476
+			/* coverity[check_return : FALSE] */
2458 2477
 			recv(rtpp_socks[node->idx], buf, sizeof(buf) - 1, 0);
2459 2478
 			fds[0].revents = 0;
2460 2479
 		}
... ...
@@ -3056,8 +3075,12 @@ rtpengine_delete1_f(struct sip_msg* msg, char* str1, char* str2)
3056 3075
 	str flags;
3057 3076
 
3058 3077
 	flags.s = NULL;
3059
-	if (str1)
3060
-		get_str_fparam(&flags, msg, (fparam_t *) str1);
3078
+	if (str1) {
3079
+		if (get_str_fparam(&flags, msg, (fparam_t *) str1)) {
3080
+			LM_ERR("Error getting string parameter\n");
3081
+			return -1;
3082
+		}
3083
+	}
3061 3084
 
3062 3085
 	return rtpengine_rtpp_set_wrap(msg, rtpengine_delete_wrap, flags.s, 1);
3063 3086
 }
... ...
@@ -3072,8 +3095,12 @@ rtpengine_query1_f(struct sip_msg* msg, char* str1, char* str2)
3072 3095
 	str flags;
3073 3096
 
3074 3097
 	flags.s = NULL;
3075
-	if (str1)
3076
-		get_str_fparam(&flags, msg, (fparam_t *) str1);
3098
+	if (str1) {
3099
+		if (get_str_fparam(&flags, msg, (fparam_t *) str1)) {
3100
+			LM_ERR("Error getting string parameter\n");
3101
+			return -1;
3102
+		}
3103
+	}
3077 3104
 
3078 3105
 	return rtpengine_rtpp_set_wrap(msg, rtpengine_query_wrap, flags.s, 1);
3079 3106
 }
... ...
@@ -3227,8 +3254,12 @@ rtpengine_manage1_f(struct sip_msg *msg, char *str1, char *str2)
3227 3254
 	str flags;
3228 3255
 
3229 3256
 	flags.s = NULL;
3230
-	if (str1)
3231
-		get_str_fparam(&flags, msg, (fparam_t *) str1);
3257
+	if (str1) {
3258
+		if (get_str_fparam(&flags, msg, (fparam_t *) str1)) {
3259
+			LM_ERR("Error getting string parameter\n");
3260
+			return -1;
3261
+		}
3262
+	}
3232 3263
 
3233 3264
 	return rtpengine_rtpp_set_wrap(msg, rtpengine_manage_wrap, flags.s, 1);
3234 3265
 }
... ...
@@ -3243,8 +3274,12 @@ rtpengine_offer1_f(struct sip_msg *msg, char *str1, char *str2)
3243 3274
 	str flags;
3244 3275
 
3245 3276
 	flags.s = NULL;
3246
-	if (str1)
3247
-		get_str_fparam(&flags, msg, (fparam_t *) str1);
3277
+	if (str1) {
3278
+		if (get_str_fparam(&flags, msg, (fparam_t *) str1)) {
3279
+			LM_ERR("Error getting string parameter\n");
3280
+			return -1;
3281
+		}
3282
+	}
3248 3283
 
3249 3284
 	return rtpengine_rtpp_set_wrap(msg, rtpengine_offer_wrap, flags.s, 1);
3250 3285
 }
... ...
@@ -3263,8 +3298,12 @@ rtpengine_answer1_f(struct sip_msg *msg, char *str1, char *str2)
3263 3298
 			return -1;
3264 3299
 
3265 3300
 	flags.s = NULL;
3266
-	if (str1)
3267
-		get_str_fparam(&flags, msg, (fparam_t *) str1);
3301
+	if (str1) {
3302
+		if (get_str_fparam(&flags, msg, (fparam_t *) str1)) {
3303
+			LM_ERR("Error getting string parameter\n");
3304
+			return -1;
3305
+		}
3306
+	}
3268 3307
 
3269 3308
 	return rtpengine_rtpp_set_wrap(msg, rtpengine_answer_wrap, flags.s, 2);
3270 3309
 }