aboutsummaryrefslogtreecommitdiffstats
path: root/src/auc.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-02-21 22:57:11 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-02-22 03:25:29 +0100
commit569d3225976a8b85eaa8f7992e2a20b88aa21897 (patch)
tree8233f82d5fc470f60c06c72919fa412a2d08d016 /src/auc.c
parentec9036bdd277bab473e802f53b33f00d9c65f86f (diff)
auc_gen_vectors(): ensure sane arguments, test
In auc_gen_vectors(), add various checks that the auth data arguments passed make sense, and add unit test to verify that they work. (Caught a segfault due to NULL dereference with this.) Change-Id: I775652b6a91d382707ce32176a3fe4ef547cbca7
Diffstat (limited to 'src/auc.c')
-rw-r--r--src/auc.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/auc.c b/src/auc.c
index 3f3db34..a307931 100644
--- a/src/auc.c
+++ b/src/auc.c
@@ -36,13 +36,42 @@ int auc_compute_vectors(struct osmo_auth_vector *vec, unsigned int num_vec,
uint8_t rand[16];
int rc;
- if (aud2g->algo == OSMO_AUTH_ALG_NONE)
+ if (aud2g && (aud2g->algo == OSMO_AUTH_ALG_NONE
+ || aud2g->type == OSMO_AUTH_TYPE_NONE))
aud2g = NULL;
- if (aud3g->algo == OSMO_AUTH_ALG_NONE)
+ if (aud3g && (aud3g->algo == OSMO_AUTH_ALG_NONE
+ || aud3g->type == OSMO_AUTH_TYPE_NONE))
aud3g = NULL;
- if (!aud2g && !aud3g)
+ if (!aud2g && !aud3g) {
+ LOGP(DAUC, LOGL_ERROR, "auc_compute_vectors() called"
+ " with neither 2G nor 3G auth data available\n");
return -1;
+ }
+
+ if (aud2g && aud2g->type != OSMO_AUTH_TYPE_GSM) {
+ LOGP(DAUC, LOGL_ERROR, "auc_compute_vectors() called"
+ " with non-2G auth data passed for aud2g arg\n");
+ return -1;
+ }
+
+ if (aud3g && aud3g->type != OSMO_AUTH_TYPE_UMTS) {
+ LOGP(DAUC, LOGL_ERROR, "auc_compute_vectors() called"
+ " with non-3G auth data passed for aud3g arg\n");
+ return -1;
+ }
+
+ if ((rand_auts != NULL) != (auts != NULL)) {
+ LOGP(DAUC, LOGL_ERROR, "auc_compute_vectors() with only one"
+ " of AUTS and AUTS_RAND given, need both or neither\n");
+ return -1;
+ }
+
+ if (auts && !aud3g) {
+ LOGP(DAUC, LOGL_ERROR, "auc_compute_vectors() with AUTS called"
+ " but no 3G auth data passed\n");
+ return -1;
+ }
/* compute quintuples */
for (i = 0; i < num_vec; i++) {