Skip to content

Commit

Permalink
misc: replace magic number with DEVLIST_LEN
Browse files Browse the repository at this point in the history
Add preprocessor constant `DEVLIST_LEN` to replace magic number 64 in
allocations of device info list.
  • Loading branch information
eumpf0 authored and LDVG committed Jan 16, 2024
1 parent 89bec9f commit f6f73bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pamu2fcfg/pamu2fcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_LEN, &ndevs);
if (r != FIDO_OK) {
fprintf(stderr, "Unable to discover device(s), %s (%d)\n", fido_strerr(r),
r);
Expand All @@ -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_LEN, &ndevs);
if (r != FIDO_OK) {
fprintf(stderr, "\nUnable to discover device(s), %s (%d)",
fido_strerr(r), r);
Expand Down
10 changes: 5 additions & 5 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_LEN, &ndevs);
if (r != FIDO_OK) {
debug_dbg(cfg, "Unable to discover device(s), %s (%d)", fido_strerr(r), r);
goto out;
Expand All @@ -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_LEN + 1, sizeof(fido_dev_t *));
if (!authlist) {
debug_dbg(cfg, "Unable to allocate authenticator list");
goto out;
Expand Down Expand Up @@ -1267,13 +1267,13 @@ int do_authentication(const cfg_t *cfg, const device_t *devices,

fido_dev_info_free(&devlist, ndevs);

devlist = fido_dev_info_new(64);
devlist = fido_dev_info_new(DEVLIST_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_LEN, &ndevs);
if (r != FIDO_OK) {
debug_dbg(cfg, "Unable to discover device(s), %s (%d)", fido_strerr(r),
r);
Expand Down
2 changes: 2 additions & 0 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#define DEFAULT_ORIGIN_PREFIX "pam://"
#define SSH_ORIGIN "ssh:"

#define DEVLIST_LEN 64

typedef struct {
unsigned max_devs;
int manual;
Expand Down

0 comments on commit f6f73bf

Please sign in to comment.