aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-01-13 12:58:30 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2020-01-13 12:58:35 +0100
commit4c273d643739e0c82456aaecf6937b3da2b32d15 (patch)
tree19ca11df65019b1d0575776fd0bcc374166e22b4
parentbc84ef264e508ee55146d385a4cd81f829478094 (diff)
ss7: Improve checks in osmo_ss7_asp_peer_add_host()
* Introduce check to make sure we don't write out of peer->host bounds. * Clean up any/specific address checks, it should be more clear now. Change-Id: I3ecb94267acbec6ecf2134b08110f24f131cd8cf
-rw-r--r--src/osmo_ss7.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index 70ec847..b7d69cb 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -1149,19 +1149,25 @@ int osmo_ss7_asp_peer_add_host(struct osmo_ss7_asp_peer *peer, void *talloc_ctx,
bool new_is_any = !host || !strcmp(host, "0.0.0.0");
bool iter_is_any;
- /* Makes no sense to have INET_ANY and specific addresses in the set */
- for (i = 0; i < peer->host_cnt; i++) {
- iter_is_any = !peer->host[i] ||
- !strcmp(peer->host[i], "0.0.0.0");
- if (new_is_any && iter_is_any)
- return -EINVAL;
- if (!new_is_any && iter_is_any)
- return -EINVAL;
- }
- /* Makes no sense to have INET_ANY many times */
- if (new_is_any && peer->host_cnt)
+ if (peer->host_cnt >= ARRAY_SIZE(peer->host))
+ return -EINVAL;
+
+ /* Makes no sense to have INET_ANY many times, or INET_ANY together with
+ specific addresses: */
+ if (new_is_any && peer->host_cnt != 0)
return -EINVAL;
+ /* Makes no sense to add specific address to set if INET_ANY is
+ already set: */
+ if (!new_is_any) {
+ for (i = 0; i < peer->host_cnt; i++) {
+ iter_is_any = !peer->host[i] ||
+ !strcmp(peer->host[i], "0.0.0.0");
+ if (iter_is_any)
+ return -EINVAL;
+ }
+ }
+
osmo_talloc_replace_string(talloc_ctx, &peer->host[peer->host_cnt], host);
peer->host_cnt++;
return 0;