Skip to content

Commit f6f73bf

Browse files
Elias RumpfLDVG
Elias Rumpf
authored andcommitted
misc: replace magic number with DEVLIST_LEN
Add preprocessor constant `DEVLIST_LEN` to replace magic number 64 in allocations of device info list.
1 parent 89bec9f commit f6f73bf

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

pamu2fcfg/pamu2fcfg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,13 @@ int main(int argc, char *argv[]) {
467467
parse_args(argc, argv, &args);
468468
fido_init(args.debug ? FIDO_DEBUG : 0);
469469

470-
devlist = fido_dev_info_new(64);
470+
devlist = fido_dev_info_new(DEVLIST_LEN);
471471
if (!devlist) {
472472
fprintf(stderr, "error: fido_dev_info_new failed\n");
473473
goto err;
474474
}
475475

476-
r = fido_dev_info_manifest(devlist, 64, &ndevs);
476+
r = fido_dev_info_manifest(devlist, DEVLIST_LEN, &ndevs);
477477
if (r != FIDO_OK) {
478478
fprintf(stderr, "Unable to discover device(s), %s (%d)\n", fido_strerr(r),
479479
r);
@@ -489,7 +489,7 @@ int main(int argc, char *argv[]) {
489489
fflush(stderr);
490490
sleep(FREQUENCY);
491491

492-
r = fido_dev_info_manifest(devlist, 64, &ndevs);
492+
r = fido_dev_info_manifest(devlist, DEVLIST_LEN, &ndevs);
493493
if (r != FIDO_OK) {
494494
fprintf(stderr, "\nUnable to discover device(s), %s (%d)",
495495
fido_strerr(r), r);

util.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,13 +1155,13 @@ int do_authentication(const cfg_t *cfg, const device_t *devices,
11551155
#endif
11561156
memset(&pk, 0, sizeof(pk));
11571157

1158-
devlist = fido_dev_info_new(64);
1158+
devlist = fido_dev_info_new(DEVLIST_LEN);
11591159
if (!devlist) {
11601160
debug_dbg(cfg, "Unable to allocate devlist");
11611161
goto out;
11621162
}
11631163

1164-
r = fido_dev_info_manifest(devlist, 64, &ndevs);
1164+
r = fido_dev_info_manifest(devlist, DEVLIST_LEN, &ndevs);
11651165
if (r != FIDO_OK) {
11661166
debug_dbg(cfg, "Unable to discover device(s), %s (%d)", fido_strerr(r), r);
11671167
goto out;
@@ -1171,7 +1171,7 @@ int do_authentication(const cfg_t *cfg, const device_t *devices,
11711171

11721172
debug_dbg(cfg, "Device max index is %zu", ndevs);
11731173

1174-
authlist = calloc(64 + 1, sizeof(fido_dev_t *));
1174+
authlist = calloc(DEVLIST_LEN + 1, sizeof(fido_dev_t *));
11751175
if (!authlist) {
11761176
debug_dbg(cfg, "Unable to allocate authenticator list");
11771177
goto out;
@@ -1267,13 +1267,13 @@ int do_authentication(const cfg_t *cfg, const device_t *devices,
12671267

12681268
fido_dev_info_free(&devlist, ndevs);
12691269

1270-
devlist = fido_dev_info_new(64);
1270+
devlist = fido_dev_info_new(DEVLIST_LEN);
12711271
if (!devlist) {
12721272
debug_dbg(cfg, "Unable to allocate devlist");
12731273
goto out;
12741274
}
12751275

1276-
r = fido_dev_info_manifest(devlist, 64, &ndevs);
1276+
r = fido_dev_info_manifest(devlist, DEVLIST_LEN, &ndevs);
12771277
if (r != FIDO_OK) {
12781278
debug_dbg(cfg, "Unable to discover device(s), %s (%d)", fido_strerr(r),
12791279
r);

util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#define DEFAULT_ORIGIN_PREFIX "pam://"
2222
#define SSH_ORIGIN "ssh:"
2323

24+
#define DEVLIST_LEN 64
25+
2426
typedef struct {
2527
unsigned max_devs;
2628
int manual;

0 commit comments

Comments
 (0)