use fido_log_error() in a few more places

This commit is contained in:
pedro martelletto
2020-12-28 09:14:25 +01:00
parent fb59c5a758
commit 7032a63c1e
10 changed files with 185 additions and 85 deletions

View File

@@ -6,6 +6,7 @@
#include <assert.h>
#include <cbor.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -166,6 +167,7 @@ mutate_string(char *s)
s[n] = '\0';
}
/* XXX should fail, but doesn't */
static int
buf_read(unsigned char *ptr, size_t len, int ms)
{
@@ -191,8 +193,10 @@ buf_write(const unsigned char *ptr, size_t len)
{
consume(ptr, len);
if (uniform_random(400) < 1)
if (uniform_random(400) < 1) {
errno = EIO;
return -1;
}
return (int)len;
}

View File

@@ -9,6 +9,7 @@
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usbhid.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
@@ -39,12 +40,11 @@ is_fido(int fd)
ugd.ugd_maxlen = sizeof(buf);
if (ioctl(fd, USB_GET_REPORT_DESC, &ugd) == -1) {
fido_log_debug("%s: ioctl", __func__);
fido_log_error(errno, "%s: ioctl", __func__);
return (false);
}
if (ugd.ugd_actlen > sizeof(buf) ||
fido_hid_get_usage(ugd.ugd_data, ugd.ugd_actlen, &usage_page) < 0) {
if (ugd.ugd_actlen > sizeof(buf) || fido_hid_get_usage(ugd.ugd_data,
ugd.ugd_actlen, &usage_page) < 0) {
fido_log_debug("%s: fido_hid_get_usage", __func__);
return (false);
}
@@ -66,6 +66,7 @@ copy_info(fido_dev_info_t *di, const char *path)
goto fail;
if (ioctl(fd, USB_GET_DEVICEINFO, &udi) == -1) {
fido_log_error(errno, "%s: ioctl", __func__);
strlcpy(udi.udi_vendor, "FreeBSD", sizeof(udi.udi_vendor));
strlcpy(udi.udi_product, "uhid(4)", sizeof(udi.udi_product));
udi.udi_vendorNo = 0x0b5d; /* stolen from PCI_VENDOR_OPENBSD */
@@ -130,6 +131,7 @@ fido_hid_open(const char *path)
char buf[64];
struct hid_freebsd *ctx;
struct usb_gen_descriptor ugd;
int r;
memset(&buf, 0, sizeof(buf));
memset(&ugd, 0, sizeof(ugd));
@@ -146,10 +148,12 @@ fido_hid_open(const char *path)
ugd.ugd_data = buf;
ugd.ugd_maxlen = sizeof(buf);
if (ioctl(ctx->fd, USB_GET_REPORT_DESC, &ugd) == -1 ||
if ((r = ioctl(ctx->fd, USB_GET_REPORT_DESC, &ugd) == -1) ||
ugd.ugd_actlen > sizeof(buf) ||
fido_hid_get_report_len(ugd.ugd_data, ugd.ugd_actlen,
&ctx->report_in_len, &ctx->report_out_len) < 0) {
if (r == -1)
fido_log_error(errno, "%s: ioctl", __func__);
fido_log_debug("%s: using default report sizes", __func__);
ctx->report_in_len = CTAP_MAX_REPORT_LEN;
ctx->report_out_len = CTAP_MAX_REPORT_LEN;
@@ -163,7 +167,9 @@ fido_hid_close(void *handle)
{
struct hid_freebsd *ctx = handle;
close(ctx->fd);
if (close(ctx->fd) == -1)
fido_log_error(errno, "%s: close", __func__);
free(ctx);
}
@@ -194,8 +200,13 @@ fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms)
return (-1);
}
if ((r = read(ctx->fd, buf, len)) == -1 || (size_t)r != len) {
fido_log_debug("%s: read", __func__);
if ((r = read(ctx->fd, buf, len)) == -1)
fido_log_error(errno, "%s: read", __func__);
return (-1);
}
if (r < 0 || (size_t)r != len) {
fido_log_debug("%s: %zd != %zu", __func__, r, len);
return (-1);
}
@@ -213,9 +224,13 @@ fido_hid_write(void *handle, const unsigned char *buf, size_t len)
return (-1);
}
if ((r = write(ctx->fd, buf + 1, len - 1)) == -1 ||
(size_t)r != len - 1) {
fido_log_debug("%s: write", __func__);
if ((r = write(ctx->fd, buf + 1, len - 1)) == -1) {
fido_log_error(errno, "%s: write", __func__);
return (-1);
}
if (r < 0 || (size_t)r != len - 1) {
fido_log_debug("%s: %zd != %zu", __func__, r, len - 1);
return (-1);
}

View File

@@ -11,6 +11,7 @@
#include <fcntl.h>
#endif
#include <errno.h>
#include <hidapi.h>
#include <stdlib.h>
#include <string.h>
@@ -111,14 +112,14 @@ get_report_descriptor(const char *path, struct hidraw_report_descriptor *hrd)
if (ioctl(fd, HIDIOCGRDESCSIZE, &s) < 0 || s < 0 ||
(unsigned)s > HID_MAX_DESCRIPTOR_SIZE) {
fido_log_debug("%s: ioctl HIDIOCGRDESCSIZE", __func__);
fido_log_error(errno, "%s: ioctl HIDIOCGRDESCSIZE", __func__);
goto fail;
}
hrd->size = (unsigned)s;
if (ioctl(fd, HIDIOCGRDESC, hrd) < 0) {
fido_log_debug("%s: ioctl HIDIOCGRDESC", __func__);
fido_log_error(errno, "%s: ioctl HIDIOCGRDESC", __func__);
goto fail;
}

View File

@@ -10,6 +10,7 @@
#include <linux/hidraw.h>
#include <linux/input.h>
#include <errno.h>
#include <libudev.h>
#include <string.h>
#include <unistd.h>
@@ -29,16 +30,20 @@ get_report_descriptor(int fd, struct hidraw_report_descriptor *hrd)
{
int s = -1;
if (ioctl(fd, HIDIOCGRDESCSIZE, &s) < 0 || s < 0 ||
(unsigned)s > HID_MAX_DESCRIPTOR_SIZE) {
fido_log_debug("%s: ioctl HIDIOCGRDESCSIZE", __func__);
if (ioctl(fd, HIDIOCGRDESCSIZE, &s) == -1) {
fido_log_error(errno, "%s: ioctl HIDIOCGRDESCSIZE", __func__);
return (-1);
}
if (s < 0 || (unsigned)s > HID_MAX_DESCRIPTOR_SIZE) {
fido_log_debug("%s: HIDIOCGRDESCSIZE %d", __func__, s);
return (-1);
}
hrd->size = (unsigned)s;
if (ioctl(fd, HIDIOCGRDESC, hrd) < 0) {
fido_log_debug("%s: ioctl HIDIOCGRDESC", __func__);
if (ioctl(fd, HIDIOCGRDESC, hrd) == -1) {
fido_log_error(errno, "%s: ioctl HIDIOCGRDESC", __func__);
return (-1);
}
@@ -61,7 +66,8 @@ is_fido(const char *path)
fido_hid_get_usage(hrd.value, hrd.size, &usage_page) < 0)
usage_page = 0;
close(fd);
if (close(fd) == -1)
fido_log_error(errno, "%s: close", __func__);
return (usage_page == 0xf1d0);
}
@@ -259,7 +265,9 @@ fido_hid_close(void *handle)
{
struct hid_linux *ctx = handle;
close(ctx->fd);
if (close(ctx->fd) == -1)
fido_log_error(errno, "%s: close", __func__);
free(ctx);
}
@@ -290,8 +298,13 @@ fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms)
return (-1);
}
if ((r = read(ctx->fd, buf, len)) < 0 || (size_t)r != len) {
fido_log_debug("%s: read", __func__);
if ((r = read(ctx->fd, buf, len)) == -1) {
fido_log_error(errno, "%s: read", __func__);
return (-1);
}
if (r < 0 || (size_t)r != len) {
fido_log_debug("%s: %zd != %zu", __func__, r, len);
return (-1);
}
@@ -309,8 +322,13 @@ fido_hid_write(void *handle, const unsigned char *buf, size_t len)
return (-1);
}
if ((r = write(ctx->fd, buf, len)) < 0 || (size_t)r != len) {
fido_log_debug("%s: write", __func__);
if ((r = write(ctx->fd, buf, len)) == -1) {
fido_log_error(errno, "%s: write", __func__);
return (-1);
}
if (r < 0 || (size_t)r != len) {
fido_log_debug("%s: %zd != %zu", __func__, r, len);
return (-1);
}

View File

@@ -47,7 +47,7 @@ is_fido(int fd)
memset(&ucrd, 0, sizeof(ucrd));
if (ioctl(fd, USB_GET_REPORT_DESC, &ucrd) == -1) {
fido_log_debug("%s: ioctl", __func__);
fido_log_error(errno, "%s: ioctl", __func__);
return (false);
}
@@ -72,7 +72,7 @@ is_fido(int fd)
* the output interrupt pipe as we need.
*/
if (ioctl(fd, USB_HID_SET_RAW, &raw) == -1) {
fido_log_debug("%s: unable to set raw", __func__);
fido_log_error(errno, "%s: unable to set raw", __func__);
return (false);
}
@@ -92,8 +92,10 @@ copy_info(fido_dev_info_t *di, const char *path)
if ((fd = fido_hid_unix_open(path)) == -1 || is_fido(fd) == 0)
goto fail;
if (ioctl(fd, USB_GET_DEVICEINFO, &udi) == -1)
if (ioctl(fd, USB_GET_DEVICEINFO, &udi) == -1) {
fido_log_error(errno, "%s: ioctl", __func__);
goto fail;
}
if ((di->path = strdup(path)) == NULL ||
(di->manufacturer = strdup(udi.udi_vendor)) == NULL ||
@@ -105,8 +107,8 @@ copy_info(fido_dev_info_t *di, const char *path)
ok = 0;
fail:
if (fd != -1)
close(fd);
if (fd != -1 && close(fd) == -1)
fido_log_error(errno, "%s: close", __func__);
if (ok < 0) {
free(di->path);
@@ -183,7 +185,7 @@ terrible_ping_kludge(struct hid_netbsd *ctx)
pfd.fd = ctx->fd;
pfd.events = POLLIN;
if ((n = poll(&pfd, 1, 100)) == -1) {
fido_log_debug("%s: poll: %d", __func__, errno);
fido_log_error(errno, "%s: poll", __func__);
return -1;
} else if (n == 0) {
fido_log_debug("%s: timed out", __func__);
@@ -209,6 +211,7 @@ fido_hid_open(const char *path)
{
struct hid_netbsd *ctx;
struct usb_ctl_report_desc ucrd;
int r;
memset(&ucrd, 0, sizeof(ucrd));
@@ -218,11 +221,13 @@ fido_hid_open(const char *path)
return (NULL);
}
if (ioctl(ctx->fd, USB_GET_REPORT_DESC, &ucrd) == -1 ||
if ((r = ioctl(ctx->fd, USB_GET_REPORT_DESC, &ucrd)) == -1 ||
ucrd.ucrd_size < 0 ||
(size_t)ucrd.ucrd_size > sizeof(ucrd.ucrd_data) ||
fido_hid_get_report_len(ucrd.ucrd_data, (size_t)ucrd.ucrd_size,
&ctx->report_in_len, &ctx->report_out_len) < 0) {
if (r == -1)
fido_log_error(errno, "%s: ioctl", __func__);
fido_log_debug("%s: using default report sizes", __func__);
ctx->report_in_len = CTAP_MAX_REPORT_LEN;
ctx->report_out_len = CTAP_MAX_REPORT_LEN;
@@ -246,7 +251,9 @@ fido_hid_close(void *handle)
{
struct hid_netbsd *ctx = handle;
close(ctx->fd);
if (close(ctx->fd) == -1)
fido_log_error(errno, "%s: close", __func__);
free(ctx);
}
@@ -277,8 +284,13 @@ fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms)
return (-1);
}
if ((r = read(ctx->fd, buf, len)) == -1 || (size_t)r != len) {
fido_log_debug("%s: read", __func__);
if ((r = read(ctx->fd, buf, len)) == -1) {
fido_log_error(errno, "%s: read", __func__);
return (-1);
}
if (r < 0 || (size_t)r != len) {
fido_log_error(errno, "%s: %zd != %zu", __func__, r, len);
return (-1);
}
@@ -296,9 +308,13 @@ fido_hid_write(void *handle, const unsigned char *buf, size_t len)
return (-1);
}
if ((r = write(ctx->fd, buf + 1, len - 1)) == -1 ||
(size_t)r != len - 1) {
fido_log_debug("%s: write", __func__);
if ((r = write(ctx->fd, buf + 1, len - 1)) == -1) {
fido_log_error(errno, "%s: write", __func__);
return (-1);
}
if (r < 0 || (size_t)r != len - 1) {
fido_log_error(errno, "%s: %zd != %zu", __func__, r, len - 1);
return (-1);
}

View File

@@ -46,13 +46,15 @@ fido_hid_manifest(fido_dev_info_t *devlist, size_t ilen, size_t *olen)
if ((fd = fido_hid_unix_open(path)) == -1)
continue;
memset(&udi, 0, sizeof(udi));
if (ioctl(fd, USB_GET_DEVICEINFO, &udi) != 0) {
fido_log_debug("%s: get device info %s: %d", __func__,
path, errno);
close(fd);
if (ioctl(fd, USB_GET_DEVICEINFO, &udi) == -1) {
fido_log_error(errno, "%s: get device info %s",
__func__, path);
if (close(fd) == -1)
fido_log_error(errno, "%s: close", __func__);
continue;
}
close(fd);
if (close(fd) == -1)
fido_log_error(errno, "%s: close", __func__);
fido_log_debug("%s: %s: bus = 0x%02x, addr = 0x%02x",
__func__, path, udi.udi_bus, udi.udi_addr);
@@ -122,7 +124,7 @@ terrible_ping_kludge(struct hid_openbsd *ctx)
pfd.fd = ctx->fd;
pfd.events = POLLIN;
if ((n = poll(&pfd, 1, 100)) == -1) {
fido_log_debug("%s: poll: %d", __func__, errno);
fido_log_error(errno, "%s: poll", __func__);
return -1;
} else if (n == 0) {
fido_log_debug("%s: timed out", __func__);
@@ -175,7 +177,9 @@ fido_hid_close(void *handle)
{
struct hid_openbsd *ctx = (struct hid_openbsd *)handle;
close(ctx->fd);
if (close(ctx->fd) == -1)
fido_log_error(errno, "%s: close", __func__);
free(ctx);
}
@@ -201,10 +205,17 @@ fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms)
len, ctx->report_in_len);
return (-1);
}
if ((r = read(ctx->fd, buf, len)) == -1 || (size_t)r != len) {
fido_log_debug("%s: read: %d", __func__, errno);
if ((r = read(ctx->fd, buf, len)) == -1) {
fido_log_error(errno, "%s: read", __func__);
return (-1);
}
if (r < 0 || (size_t)r != len) {
fido_log_debug("%s: %zd != %zu", __func__, r, len);
return (-1);
}
return ((int)len);
}
@@ -219,11 +230,17 @@ fido_hid_write(void *handle, const unsigned char *buf, size_t len)
len, ctx->report_out_len);
return (-1);
}
if ((r = write(ctx->fd, buf + 1, len - 1)) == -1 ||
(size_t)r != len - 1) {
fido_log_debug("%s: write: %d", __func__, errno);
if ((r = write(ctx->fd, buf + 1, len - 1)) == -1) {
fido_log_error(errno, "%s: write", __func__);
return (-1);
}
if (r < 0 || (size_t)r != len - 1) {
fido_log_debug("%s: %zd != %zu", __func__, r, len - 1);
return (-1);
}
return ((int)len);
}

View File

@@ -6,6 +6,7 @@
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
@@ -315,9 +316,13 @@ report_callback(void *context, IOReturn result, void *dev, IOHIDReportType type,
return;
}
if ((r = write(ctx->report_pipe[1], ptr, (size_t)len)) < 0 ||
(size_t)r != (size_t)len) {
fido_log_debug("%s: write", __func__);
if ((r = write(ctx->report_pipe[1], ptr, (size_t)len)) == -1) {
fido_log_error(errno, "%s: write", __func__);
return;
}
if (r < 0 || (size_t)r != (size_t)len) {
fido_log_debug("%s: %zd != %zu", __func__, r, (size_t)len);
return;
}
}
@@ -338,12 +343,12 @@ set_nonblock(int fd)
int flags;
if ((flags = fcntl(fd, F_GETFL)) == -1) {
fido_log_debug("%s: fcntl F_GETFL", __func__);
fido_log_error(errno, "%s: fcntl F_GETFL", __func__);
return (-1);
}
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
fido_log_debug("%s: fcntl, F_SETFL", __func__);
fido_log_error(errno, "%s: fcntl F_SETFL", __func__);
return (-1);
}
@@ -356,7 +361,7 @@ disable_sigpipe(int fd)
int disabled = 1;
if (fcntl(fd, F_SETNOSIGPIPE, &disabled) == -1) {
fido_log_debug("%s: fcntl F_SETNOSIGPIPE", __func__);
fido_log_error(errno, "%s: fcntl F_SETNOSIGPIPE", __func__);
return (-1);
}
@@ -381,7 +386,7 @@ fido_hid_open(const char *path)
ctx->report_pipe[1] = -1;
if (pipe(ctx->report_pipe) == -1) {
fido_log_debug("%s: pipe", __func__);
fido_log_error(errno, "%s: pipe", __func__);
goto fail;
}
@@ -520,8 +525,13 @@ fido_hid_read(void *handle, unsigned char *buf, size_t len, int ms)
IOHIDDeviceUnscheduleFromRunLoop(ctx->ref, CFRunLoopGetCurrent(),
ctx->loop_id);
if ((r = read(ctx->report_pipe[0], buf, len)) < 0 || (size_t)r != len) {
fido_log_debug("%s: read", __func__);
if ((r = read(ctx->report_pipe[0], buf, len)) == -1) {
fido_log_error(errno, "%s: read", __func__);
return (-1);
}
if (r < 0 || (size_t)r != len) {
fido_log_debug("%s: %zd != %zu", __func__, r, len);
return (-1);
}

View File

@@ -45,13 +45,15 @@ fido_hid_unix_open(const char *path)
if (fstat(fd, &st) == -1) {
fido_log_error(errno, "%s: fstat %s", __func__, path);
close(fd);
if (close(fd) == -1)
fido_log_error(errno, "%s: close", __func__);
return (-1);
}
if (S_ISCHR(st.st_mode) == 0) {
fido_log_debug("%s: S_ISCHR %s", __func__, path);
close(fd);
if (close(fd) == -1)
fido_log_error(errno, "%s: close", __func__);
return (-1);
}

View File

@@ -343,9 +343,12 @@ nlmsg_tx(int fd, const nlmsgbuf_t *m)
{
ssize_t r;
if ((r = WRITE(fd, nlmsg_ptr(m), nlmsg_len(m))) < 0 ||
(size_t)r != nlmsg_len(m)) {
fido_log_debug("%s: write", __func__);
if ((r = WRITE(fd, nlmsg_ptr(m), nlmsg_len(m))) == -1) {
fido_log_error(errno, "%s: write", __func__);
return (-1);
}
if (r < 0 || (size_t)r != nlmsg_len(m)) {
fido_log_debug("%s: %zd != %zu", __func__, r, nlmsg_len(m));
return (-1);
}
fido_log_debug("%s: buf=%p, len=%zu", __func__, nlmsg_ptr(m),
@@ -368,8 +371,8 @@ nlmsg_rx(int fd, unsigned char *ptr, size_t len, int ms)
fido_log_debug("%s: fido_hid_unix_wait", __func__);
return (-1);
}
if ((r = READ(fd, ptr, len)) < 0) {
fido_log_debug("%s: read", __func__);
if ((r = READ(fd, ptr, len)) == -1) {
fido_log_error(errno, "%s: read %zd", __func__, r);
return (-1);
}
fido_log_debug("%s: buf=%p, len=%zu", __func__, (void *)ptr, (size_t)r);
@@ -695,7 +698,7 @@ fido_nl_get_nfc_target(fido_nl_t *nl, uint32_t dev, uint32_t *target)
#ifndef FIDO_FUZZ
if (setsockopt(nl->fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP,
&nl->nfc_mcastgrp, sizeof(nl->nfc_mcastgrp)) == -1) {
fido_log_debug("%s: setsockopt add", __func__);
fido_log_error(errno, "%s: setsockopt add", __func__);
return (-1);
}
#endif
@@ -703,7 +706,7 @@ fido_nl_get_nfc_target(fido_nl_t *nl, uint32_t dev, uint32_t *target)
#ifndef FIDO_FUZZ
if (setsockopt(nl->fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP,
&nl->nfc_mcastgrp, sizeof(nl->nfc_mcastgrp)) == -1) {
fido_log_debug("%s: setsockopt drop", __func__);
fido_log_error(errno, "%s: setsockopt drop", __func__);
return (-1);
}
#endif
@@ -737,8 +740,8 @@ fido_nl_free(fido_nl_t **nlp)
if (nlp == NULL || (nl = *nlp) == NULL)
return;
if (nl->fd != -1)
close(nl->fd);
if (nl->fd != -1 && close(nl->fd) == -1)
fido_log_error(errno, "%s: close", __func__);
free(nl);
*nlp = NULL;
@@ -754,13 +757,13 @@ fido_nl_new(void)
return (NULL);
if ((nl->fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC,
NETLINK_GENERIC)) == -1) {
fido_log_debug("%s: socket", __func__);
fido_log_error(errno, "%s: socket", __func__);
goto fail;
}
nl->saddr.nl_family = AF_NETLINK;
if (bind(nl->fd, (struct sockaddr *)&nl->saddr,
sizeof(nl->saddr)) == -1) {
fido_log_debug("%s: bind", __func__);
fido_log_error(errno, "%s: bind", __func__);
goto fail;
}
if (nl_get_nfc_family(nl->fd, &nl->nfc_type, &nl->nfc_mcastgrp) < 0) {

View File

@@ -479,13 +479,15 @@ nfc_target_connect(struct nfc_linux *ctx)
sa.nfc_protocol = NFC_PROTO_ISO14443;
if ((ctx->fd = socket(AF_NFC, SOCK_SEQPACKET | SOCK_CLOEXEC,
NFC_SOCKPROTO_RAW)) == -1 ||
connect(ctx->fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
fido_log_debug("%s: connect", __func__);
if (ctx->fd != -1) {
close(ctx->fd);
ctx->fd = -1;
}
NFC_SOCKPROTO_RAW)) == -1) {
fido_log_error(errno, "%s: socket", __func__);
return (-1);
}
if (connect(ctx->fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
fido_log_error(errno, "%s: connect", __func__);
if (close(ctx->fd) == -1)
fido_log_error(errno, "%s: close", __func__);
ctx->fd = -1;
return (-1);
}
@@ -499,8 +501,8 @@ nfc_free(struct nfc_linux **ctx_p)
if (ctx_p == NULL || (ctx = *ctx_p) == NULL)
return;
if (ctx->fd != -1)
close(ctx->fd);
if (ctx->fd != -1 && close(ctx->fd) == -1)
fido_log_error(errno, "%s: close", __func__);
if (ctx->nl != NULL)
fido_nl_free(&ctx->nl);
@@ -586,8 +588,16 @@ fido_nfc_read(void *handle, unsigned char *buf, size_t len, int ms)
fido_log_debug("%s: fido_hid_unix_wait", __func__);
return (-1);
}
if ((r = readv(ctx->fd, iov, nitems(iov))) < 1 || preamble != 0x00) {
fido_log_debug("%s: readv", __func__);
if ((r = readv(ctx->fd, iov, nitems(iov))) == -1) {
fido_log_error(errno, "%s: read", __func__);
return (-1);
}
if (r < 1) {
fido_log_debug("%s: %zd < 1", __func__, r);
return (-1);
}
if (preamble != 0x00) {
fido_log_debug("%s: preamble", __func__);
return (-1);
}
@@ -611,8 +621,12 @@ fido_nfc_write(void *handle, const unsigned char *buf, size_t len)
fido_log_debug("%s: len", __func__);
return (-1);
}
if ((r = write(ctx->fd, buf, len)) < 0 || (size_t)r != len) {
fido_log_debug("%s: write", __func__);
if ((r = write(ctx->fd, buf, len)) == -1) {
fido_log_error(errno, "%s: write", __func__);
return (-1);
}
if (r < 0 || (size_t)r != len) {
fido_log_debug("%s: %zd != %zu", __func__, r, len);
return (-1);
}