## Coverage Report

#### Created: 2025-03-01 02:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)

    /libfido2/src/hid_unix.c

    Line
    Count
    Source
    1
    /*
    2
     * Copyright (c) 2020 Yubico AB. All rights reserved.
    3
     * Use of this source code is governed by a BSD-style
    4
     * license that can be found in the LICENSE file.
    5
     * SPDX-License-Identifier: BSD-2-Clause
    6
     */
    7
    8
    #include <sys/stat.h>
    9
    10
    #include <errno.h>
    11
    #include <fcntl.h>
    12
    #include <poll.h>
    13
    #include <unistd.h>
    14
    15
    #include "fido.h"
    16
    17
    #ifdef __NetBSD__
    18
    #define ppoll   pollts
    19
    #endif
    20
    21
    int
    22
    fido_hid_unix_open(const char *path)
    23
    2.48M
    {
    24
    2.48M
            int fd;
    25
    2.48M
            struct stat st;
    26
    27
    2.48M
            if ((fd = open(path, O_RDWR)) == -1) {
    28
    0
                    if (errno != ENOENT && errno != ENXIO)
    29
    0
                            fido_log_error(errno, "%s: open %s", __func__, path);
    30
    0
                    return (-1);
    31
    0
            }
    32
    33
    2.48M
            if (fstat(fd, &st) == -1) {
    34
    0
                    fido_log_error(errno, "%s: fstat %s", __func__, path);
    35
    0
                    if (close(fd) == -1)
    36
    0
                            fido_log_error(errno, "%s: close", __func__);
    37
    0
                    return (-1);
    38
    0
            }
    39
    40
    2.48M
            if (S_ISCHR(st.st_mode) == 0) {
    41
    0
                    fido_log_debug("%s: S_ISCHR %s", __func__, path);
    42
    0
                    if (close(fd) == -1)
    43
    0
                            fido_log_error(errno, "%s: close", __func__);
    44
    0
                    return (-1);
    45
    0
            }
    46
    47
    2.48M
            return (fd);
    48
    2.48M
    }
    49
    50
    int
    51
    fido_hid_unix_wait(int fd, int ms, const fido_sigset_t *sigmask)
    52
    2.43M
    {
    53
    2.43M
            struct timespec ts;
    54
    2.43M
            struct pollfd pfd;
    55
    2.43M
            int r;
    56
    57
    2.43M
            memset(&pfd, 0, sizeof(pfd));
    58
    2.43M
            pfd.events = POLLIN;
    59
    2.43M
            pfd.fd = fd;
    60
    61
    2.43M
    #ifdef FIDO_FUZZ
    62
    2.43M
            return (0);
    63
    0
    #endif
    64
    0
            if (ms > -1) {
    65
    0
                    ts.tv_sec = ms / 1000;
    66
    0
                    ts.tv_nsec = (ms % 1000) * 1000000;
    67
    0
            }
    68
    69
    0
            if ((r = ppoll(&pfd, 1, ms > -1 ? &ts : NULL, sigmask)) < 1) {
    70
    0
                    if (r == -1)
    71
    0
                            fido_log_error(errno, "%s: ppoll", __func__);
    72
    0
                    return (-1);
    73
    0
            }
    74
    75
    0
            return (0);
    76
    0
    }