diff options
Diffstat (limited to 'contrib/libfido2/regress/dev.c')
-rw-r--r-- | contrib/libfido2/regress/dev.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/contrib/libfido2/regress/dev.c b/contrib/libfido2/regress/dev.c index a5dc8d6e4529..0ba552b70552 100644 --- a/contrib/libfido2/regress/dev.c +++ b/contrib/libfido2/regress/dev.c @@ -1,38 +1,58 @@ /* - * Copyright (c) 2019-2021 Yubico AB. All rights reserved. + * Copyright (c) 2019-2022 Yubico AB. All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the LICENSE file. + * SPDX-License-Identifier: BSD-2-Clause */ +#undef NDEBUG + #include <assert.h> -#include <err.h> -#include <fido.h> #include <string.h> #include <time.h> +#define _FIDO_INTERNAL + +#include <fido.h> + #include "../fuzz/wiredata_fido2.h" -#define FAKE_DEV_HANDLE ((void *)0xdeadbeef) #define REPORT_LEN (64 + 1) static uint8_t ctap_nonce[8]; static uint8_t *wiredata_ptr; static size_t wiredata_len; +static int fake_dev_handle; static int initialised; static long interval_ms; +#if defined(_MSC_VER) +static int +nanosleep(const struct timespec *rqtp, struct timespec *rmtp) +{ + if (rmtp != NULL) { + errno = EINVAL; + return (-1); + } + + Sleep((DWORD)(rqtp->tv_sec * 1000) + (DWORD)(rqtp->tv_nsec / 1000000)); + + return (0); +} +#endif + static void * dummy_open(const char *path) { (void)path; - return (FAKE_DEV_HANDLE); + return (&fake_dev_handle); } static void dummy_close(void *handle) { - assert(handle == FAKE_DEV_HANDLE); + assert(handle == &fake_dev_handle); } static int @@ -42,7 +62,7 @@ dummy_read(void *handle, unsigned char *ptr, size_t len, int ms) size_t n; long d; - assert(handle == FAKE_DEV_HANDLE); + assert(handle == &fake_dev_handle); assert(ptr != NULL); assert(len == REPORT_LEN - 1); @@ -87,7 +107,7 @@ dummy_write(void *handle, const unsigned char *ptr, size_t len) { struct timespec tv; - assert(handle == FAKE_DEV_HANDLE); + assert(handle == &fake_dev_handle); assert(ptr != NULL); assert(len == REPORT_LEN); @@ -113,7 +133,14 @@ wiredata_setup(const uint8_t *data, size_t len) assert(SIZE_MAX - len > sizeof(ctap_init_data)); assert((wiredata_ptr = malloc(sizeof(ctap_init_data) + len)) != NULL); +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:6386) +#endif memcpy(wiredata_ptr, ctap_init_data, sizeof(ctap_init_data)); +#if defined(_MSC_VER) +#pragma warning(pop) +#endif if (len) memcpy(wiredata_ptr + sizeof(ctap_init_data), data, len); |