[MERGED] openbsc[master]: fix subscriber random extension allocation range

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Sat May 13 22:09:47 UTC 2017


Neels Hofmeyr has submitted this change and it was merged.

Change subject: fix subscriber random extension allocation range
......................................................................


fix subscriber random extension allocation range

The VTY config allows above 32bit range extensions, but
db_subscriber_alloc_exten() was unable to generate extensions outside of 32bit.

Add VTY regression test and fix the problem by using proper 64bit types.

Related: OS#2253
Change-Id: I9afe6a8833004ecd2f3f936b2d5aa4de8e7dbcb0
---
M openbsc/src/libmsc/db.c
M openbsc/tests/vty_test_runner.py
2 files changed, 15 insertions(+), 4 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c
index 9fa6415..5fe2a3c 100644
--- a/openbsc/src/libmsc/db.c
+++ b/openbsc/src/libmsc/db.c
@@ -1260,13 +1260,13 @@
 			      uint64_t smax)
 {
 	dbi_result result = NULL;
-	uint32_t try;
+	uint64_t try;
 
 	for (;;) {
 		try = (rand() % (smax - smin + 1) + smin);
 		result = dbi_conn_queryf(conn,
 			"SELECT * FROM Subscriber "
-			"WHERE extension = %i",
+			"WHERE extension = %"PRIu64,
 			try
 		);
 		if (!result) {
@@ -1284,8 +1284,8 @@
 		}
 		dbi_result_free(result);
 	}
-	sprintf(subscriber->extension, "%i", try);
-	DEBUGP(DDB, "Allocated extension %i for IMSI %s.\n", try, subscriber->imsi);
+	sprintf(subscriber->extension, "%"PRIu64, try);
+	DEBUGP(DDB, "Allocated extension %"PRIu64 " for IMSI %s.\n", try, subscriber->imsi);
 	return db_sync_subscriber(subscriber);
 }
 /*
diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py
index b886911..92775d5 100644
--- a/openbsc/tests/vty_test_runner.py
+++ b/openbsc/tests/vty_test_runner.py
@@ -485,6 +485,17 @@
         self.assert_(res.find("subscriber-create-on-demand random 9999999998 9999999999"))
         self.vty.command("end")
 
+        res = self.vty.command('subscriber create imsi ' + imsi)
+        print(res)
+        self.assert_(res.find("    IMSI: " + imsi) > 0)
+        self.assert_(res.find("9999999998") > 0 or res.find("9999999999") > 0)
+        self.assert_(res.find("    Extension: ") > 0)
+
+        res = self.vty.command('subscriber imsi ' + imsi + ' delete')
+        self.assert_("" == res)
+
+        res = self.vty.command('show subscriber imsi '+imsi)
+        self.assert_(('% No subscriber found for imsi ' + imsi) == res)
 
 
     def testSubscriberSettings(self):

-- 
To view, visit https://gerrit.osmocom.org/2584
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9afe6a8833004ecd2f3f936b2d5aa4de8e7dbcb0
Gerrit-PatchSet: 1
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list