diff mbox series

[v2,15/15] provision: Detect duplicates

Message ID 20231219184016.420116-15-denkenz@gmail.com (mailing list archive)
State Changes Requested, archived
Headers show
Series [v2,01/15] build: Fix typo that breaks --fsanitize=leak check | expand

Commit Message

Denis Kenzior Dec. 19, 2023, 6:37 p.m. UTC
Duplicate contexts can't really be handled without user intervention, in
which case it is better to fail provisioning entirely.  Most vendors
will choose to ship a custom provisioning database to ensure that
duplicate contexts do not happen for the supported operators.
---
 src/provision.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/src/provision.c b/src/provision.c
index e419d15c..cd5cf569 100644
--- a/src/provision.c
+++ b/src/provision.c
@@ -25,6 +25,7 @@  bool __ofono_provision_get_settings(const char *mcc,
 	struct ofono_gprs_provision_data *contexts;
 	int r;
 	size_t i;
+	uint32_t type;
 
 	if (mcc == NULL || strlen(mcc) == 0 || mnc == NULL || strlen(mnc) == 0)
 		return false;
@@ -47,6 +48,20 @@  bool __ofono_provision_get_settings(const char *mcc,
 					ap->message_center);
 	}
 
+	/* Make sure there are no duplicates */
+	for (i = 0, type = 0; i < n_contexts; i++) {
+		struct ofono_gprs_provision_data *ap = contexts + i;
+
+		if (type & ap->type) {
+			ofono_warn("Duplicate detected for %s%s, spn: %s",
+					mcc, mnc, spn);
+			l_free(contexts);
+			return false;
+		}
+
+		type |= ap->type;
+	}
+
 	*count = n_contexts;
 	*settings = contexts;