diff --git a/pamu2fcfg/pamu2fcfg.c b/pamu2fcfg/pamu2fcfg.c index 74d6ab4..123496c 100644 --- a/pamu2fcfg/pamu2fcfg.c +++ b/pamu2fcfg/pamu2fcfg.c @@ -467,13 +467,13 @@ int main(int argc, char *argv[]) { parse_args(argc, argv, &args); fido_init(args.debug ? FIDO_DEBUG : 0); - devlist = fido_dev_info_new(64); + devlist = fido_dev_info_new(DEVLIST_ALLOC_INITIAL_LEN); if (!devlist) { fprintf(stderr, "error: fido_dev_info_new failed\n"); goto err; } - r = fido_dev_info_manifest(devlist, 64, &ndevs); + r = fido_dev_info_manifest(devlist, DEVLIST_ALLOC_INITIAL_LEN, &ndevs); if (r != FIDO_OK) { fprintf(stderr, "Unable to discover device(s), %s (%d)\n", fido_strerr(r), r); @@ -489,7 +489,7 @@ int main(int argc, char *argv[]) { fflush(stderr); sleep(FREQUENCY); - r = fido_dev_info_manifest(devlist, 64, &ndevs); + r = fido_dev_info_manifest(devlist, DEVLIST_ALLOC_INITIAL_LEN, &ndevs); if (r != FIDO_OK) { fprintf(stderr, "\nUnable to discover device(s), %s (%d)", fido_strerr(r), r); @@ -564,7 +564,7 @@ int main(int argc, char *argv[]) { err: if (dev != NULL) fido_dev_close(dev); - fido_dev_info_free(&devlist, ndevs); + fido_dev_info_free(&devlist, DEVLIST_ALLOC_INITIAL_LEN); fido_cred_free(&cred); fido_dev_free(&dev); diff --git a/util.c b/util.c index f3ea20f..8997c00 100644 --- a/util.c +++ b/util.c @@ -1155,13 +1155,13 @@ int do_authentication(const cfg_t *cfg, const device_t *devices, #endif memset(&pk, 0, sizeof(pk)); - devlist = fido_dev_info_new(64); + devlist = fido_dev_info_new(DEVLIST_ALLOC_INITIAL_LEN); if (!devlist) { debug_dbg(cfg, "Unable to allocate devlist"); goto out; } - r = fido_dev_info_manifest(devlist, 64, &ndevs); + r = fido_dev_info_manifest(devlist, DEVLIST_ALLOC_INITIAL_LEN, &ndevs); if (r != FIDO_OK) { debug_dbg(cfg, "Unable to discover device(s), %s (%d)", fido_strerr(r), r); goto out; @@ -1171,7 +1171,7 @@ int do_authentication(const cfg_t *cfg, const device_t *devices, debug_dbg(cfg, "Device max index is %zu", ndevs); - authlist = calloc(64 + 1, sizeof(fido_dev_t *)); + authlist = calloc(DEVLIST_ALLOC_INITIAL_LEN + 1, sizeof(fido_dev_t *)); if (!authlist) { debug_dbg(cfg, "Unable to allocate authenticator list"); goto out; @@ -1265,15 +1265,15 @@ int do_authentication(const cfg_t *cfg, const device_t *devices, i++; - fido_dev_info_free(&devlist, ndevs); + fido_dev_info_free(&devlist, DEVLIST_ALLOC_INITIAL_LEN); - devlist = fido_dev_info_new(64); + devlist = fido_dev_info_new(DEVLIST_ALLOC_INITIAL_LEN); if (!devlist) { debug_dbg(cfg, "Unable to allocate devlist"); goto out; } - r = fido_dev_info_manifest(devlist, 64, &ndevs); + r = fido_dev_info_manifest(devlist, DEVLIST_ALLOC_INITIAL_LEN, &ndevs); if (r != FIDO_OK) { debug_dbg(cfg, "Unable to discover device(s), %s (%d)", fido_strerr(r), r); @@ -1299,7 +1299,7 @@ int do_authentication(const cfg_t *cfg, const device_t *devices, out: reset_pk(&pk); fido_assert_free(&assert); - fido_dev_info_free(&devlist, ndevs); + fido_dev_info_free(&devlist, DEVLIST_ALLOC_INITIAL_LEN); if (authlist) { for (size_t j = 0; authlist[j] != NULL; j++) { diff --git a/util.h b/util.h index cb8572b..af88df6 100644 --- a/util.h +++ b/util.h @@ -21,6 +21,8 @@ #define DEFAULT_ORIGIN_PREFIX "pam://" #define SSH_ORIGIN "ssh:" +#define DEVLIST_ALLOC_INITIAL_LEN 64 + typedef struct { unsigned max_devs; int manual;