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.orgNeels Hofmeyr has submitted this change and it was merged. Change subject: fix db_subscr_get_by_*(): clear output data; test in db_test.c ...................................................................... fix db_subscr_get_by_*(): clear output data; test in db_test.c db_subscr_get_by_*() failed to clear the out-param struct, meaning that data could remain in a struct even though it is not present in the database. Always zero out the struct before writing to it. Adjust the db_test to catch this error by writing "-invalid-data-" to each struct before running db get functions. Change-Id: I038bd437452c87841d709fcdd5ac30ab1356b2db --- M src/db_hlr.c M tests/db/db_test.c 2 files changed, 18 insertions(+), 3 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/src/db_hlr.c b/src/db_hlr.c index 71f682d..cf6e4f8 100644 --- a/src/db_hlr.c +++ b/src/db_hlr.c @@ -379,6 +379,8 @@ if (!subscr) goto out; + *subscr = (struct hlr_subscriber){}; + /* obtain the various columns */ subscr->id = sqlite3_column_int64(stmt, 0); SL3_TXT(subscr->imsi, stmt, 1); diff --git a/tests/db/db_test.c b/tests/db/db_test.c index db3318c..591418b 100644 --- a/tests/db/db_test.c +++ b/tests/db/db_test.c @@ -34,6 +34,19 @@ #define comment(fmt, args...) fprintf(stderr, "\n--- " fmt "\n\n", ## args); #define comment_end() fprintf(stderr, "===== %s: SUCCESS\n\n", __func__); +#define fill_invalid(x) _fill_invalid(&x, sizeof(x)) +static void _fill_invalid(void *dest, size_t size) +{ + uint8_t *pos = dest; + size_t remain = size; + int wrote = 0; + do { + remain -= wrote; + pos += wrote; + wrote = snprintf((void*)pos, remain, "-invalid-data"); + } while (wrote < remain); +} + /* Perform a function call and verbosely assert that its return value is as expected. * The return code is then available in g_rc. */ #define ASSERT_RC(call, expect_rc) \ @@ -53,7 +66,7 @@ #define ASSERT_SEL(by, val, expect_rc) \ do { \ int rc; \ - g_subscr = (struct hlr_subscriber){}; \ + fill_invalid(g_subscr); \ fprintf(stderr, "db_subscr_get_by_" #by "(dbc, " #val ", &g_subscr) --> " \ #expect_rc "\n"); \ rc = db_subscr_get_by_##by(dbc, val, &g_subscr); \ @@ -71,8 +84,8 @@ * The results are then available in g_aud2g and g_aud3g. */ #define ASSERT_SEL_AUD(imsi, expect_rc, expect_id) \ do { \ - g_aud2g = (struct osmo_sub_auth_data){}; \ - g_aud3g = (struct osmo_sub_auth_data){}; \ + fill_invalid(g_aud2g); \ + fill_invalid(g_aud3g); \ g_id = 0; \ ASSERT_RC(db_get_auth_data(dbc, imsi, &g_aud2g, &g_aud3g, &g_id), expect_rc); \ if (!g_rc) { \ -- To view, visit https://gerrit.osmocom.org/4230 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: I038bd437452c87841d709fcdd5ac30ab1356b2db Gerrit-PatchSet: 4 Gerrit-Project: osmo-hlr 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>