Index: dist/util.c =================================================================== RCS file: /cvsroot/src/external/bsd/pam-u2f/dist/util.c,v retrieving revision 1.4 diff -u -r1.4 util.c --- dist/util.c 24 Sep 2021 13:08:16 -0000 1.4 +++ dist/util.c 20 Aug 2022 10:50:52 -0000 @@ -1306,6 +1306,27 @@ return ok; } +#ifndef WITH_FUZZING +static FILE *log_handler_debug_file; +static void log_handler(const char *str) +{ + size_t n = strlen(str); + + /* remove linefeed */ + if (n > 0 && str[n-1] == '\n') + --n; + + /* + * Field width can only be an int, + * but printing more than INT_MAX ?? + */ + if (n > INT_MAX) + return; + + D(log_handler_debug_file, "%.*s", (int)n, str); +} +#endif + int do_authentication(const cfg_t *cfg, const device_t *devices, const unsigned n_devs, pam_handle_t *pamh) { fido_assert_t *assert = NULL; @@ -1323,7 +1344,12 @@ init_opts(&opts); #ifndef WITH_FUZZING - fido_init(cfg->debug ? FIDO_DEBUG : 0); + if (cfg->debug) { + fido_init(FIDO_DEBUG); + log_handler_debug_file = cfg->debug_file; + fido_set_log_handler(log_handler); + } else + fido_init(0); #else fido_init(0); #endif @@ -1590,7 +1616,12 @@ goto out; #ifndef WITH_FUZZING - fido_init(cfg->debug ? FIDO_DEBUG : 0); + if (cfg->debug) { + fido_init(FIDO_DEBUG); + log_handler_debug_file = cfg->debug_file; + fido_set_log_handler(log_handler); + } else + fido_init(0); #else fido_init(0); #endif