From 80f6e4fa8bbc468fe75692a4730cf822a4e0d686 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Fri, 25 Feb 2011 01:21:38 +0000 Subject: [PATCH] auth: GetLatestKey should allow NULL return values Existing callers in the code use afsconf_GetLatestKey(dir, NULL, NULL) to check for the existence of a key file. We need to permit NULL values for the return pointers to this function. Also update the tests to check for this behaviour. Change-Id: I94e74138ddeed8d167c1e6f12e297411c638e1b9 Reviewed-on: http://gerrit.openafs.org/4050 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/auth/keys.c | 7 +++++-- tests/auth/keys-t.c | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/auth/keys.c b/src/auth/keys.c index e1440dadc..aa265f10c 100644 --- a/src/auth/keys.c +++ b/src/auth/keys.c @@ -729,8 +729,11 @@ afsconf_GetLatestKey(struct afsconf_dir *dir, afs_int32 *kvno, /* XXX - Should check that the key is of the correct length */ /* Copy out the relevant details */ - *kvno = typedKey->kvno; - memcpy(key, typedKey->key.val, 8); + if (kvno != NULL) + *kvno = typedKey->kvno; + + if (key != NULL) + memcpy(key, typedKey->key.val, 8); afsconf_typedKey_put(&typedKey); diff --git a/tests/auth/keys-t.c b/tests/auth/keys-t.c index d02d6550e..2e32946fb 100644 --- a/tests/auth/keys-t.c +++ b/tests/auth/keys-t.c @@ -105,7 +105,7 @@ int main(int argc, char **argv) int code; int i; - plan(122); + plan(123); /* Create a temporary afs configuration directory */ @@ -146,6 +146,10 @@ int main(int argc, char **argv) ok(memcmp(&key, "\x19\x16\xfe\xe6\xba\x77\x2f\xfd", 8) == 0, " ... and correct key"); + /* Check that GetLatestKey works if called with NULL parameters */ + code = afsconf_GetLatestKey(dir, NULL, NULL); + is_int(0, code, "afsconf_GetLatestKey works if parameters are NULL"); + /* Verify that random access using GetKey works properly */ code = afsconf_GetKey(dir, 2, &key); is_int(0, code, "afsconf_GetKey returns successfully"); -- 2.39.5