• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 22618661228

02 Mar 2026 09:33PM UTC coverage: 42.258% (-34.4%) from 76.611%
22618661228

push

github

victorjulien
github-actions: bump actions/download-artifact from 7.0.0 to 8.0.0

Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 7.0.0 to 8.0.0.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/37930b1c2...70fc10c6e)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: 8.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

91511 of 216553 relevant lines covered (42.26%)

3416852.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/src/util-random.c
1
/* Copyright (C) 2007-2017 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17

18
/**
19
 * \file
20
 *
21
 * \author Victor Julien <victor@inliniac.net>
22
 *
23
 * Functions for getting a random value based on
24
 * SEI CERT C Coding Standard MSC30-C
25
 */
26

27
#include "suricata-common.h"
28
#include "suricata.h"
29
#include "util-random.h"
30
#include "util-debug.h"
31

32
#if !(defined(HAVE_WINCRYPT_H) &&  defined(OS_WIN32))
33
#if defined(HAVE_CLOCK_GETTIME)
34

35
static long int RandomGetClock(void)
36
{
×
37
    struct timespec ts;
×
38
    clock_gettime(CLOCK_REALTIME, &ts);
×
39

40
    // coverity[dont_call : FALSE]
41
    srandom((unsigned int)(ts.tv_nsec ^ ts.tv_sec));
×
42
    long int value = random();
×
43
    return value;
×
44
}
×
45

46
#else
47

48
static long int RandomGetPosix(void)
49
{
50
    struct timeval tv;
51
    memset(&tv, 0, sizeof(tv));
52
    gettimeofday(&tv, NULL);
53

54
    // coverity[dont_call : FALSE]
55
    srandom(tv.tv_usec ^ tv.tv_sec);
56
    long int value = random();
57
    return value;
58
}
59

60
#endif
61
#endif /* !(defined(HAVE_WINCRYPT_H) &&  defined(OS_WIN32)) */
62

63
#if defined(HAVE_WINCRYPT_H) && defined(OS_WIN32)
64
#include <wincrypt.h>
65

66
long int RandomGet(void)
67
{
68
    if (g_disable_randomness)
69
        return 0;
70

71
    HCRYPTPROV p;
72
    if (!CryptAcquireContext(&p, NULL, NULL, PROV_RSA_FULL, 0)) {
73
        DWORD err = GetLastError();
74
        SCLogDebug("CryptAcquireContext error: %" PRIu32, (uint32_t)err);
75
        if (err == (DWORD)NTE_BAD_KEYSET) {
76
            /* The key doesn't exist yet, create it */
77
            if (!CryptAcquireContext(&p, NULL, NULL, PROV_RSA_FULL,
78
                                     CRYPT_NEWKEYSET)) {
79

80
                SCLogDebug("CryptAcquireContext error: %" PRIu32,
81
                           (uint32_t)err);
82
                return -1;
83
            }
84
        } else {
85
            return -1;
86
        }
87
    }
88

89
    long int value = 0;
90
    if (!CryptGenRandom(p, sizeof(value), (BYTE *)&value)) {
91
        (void)CryptReleaseContext(p, 0);
92
        return -1;
93
    }
94

95
    (void)CryptReleaseContext(p, 0);
96

97
    return value;
98
}
99
#elif defined(HAVE_GETRANDOM)
100
long int RandomGet(void)
101
{
8,424✔
102
    if (g_disable_randomness)
8,424✔
103
        return 0;
×
104

105
    long int value = 0;
8,424✔
106
    ssize_t ret = getrandom(&value, sizeof(value), 0);
8,424✔
107
    /* ret should be sizeof(value), but if it is > 0 and < sizeof(value)
108
     * it's still better than nothing so we return what we have */
109
    if (ret <= 0) {
8,424✔
110
        if (ret == -1 && errno == ENOSYS) {
×
111
#if defined(HAVE_CLOCK_GETTIME)
×
112
            return RandomGetClock();
×
113
#else
114
            return RandomGetPosix();
115
#endif
116
        }
×
117
        return -1;
×
118
    }
×
119
    return value;
8,424✔
120
}
8,424✔
121
#elif defined(HAVE_CLOCK_GETTIME)
122
long int RandomGet(void)
123
{
124
    if (g_disable_randomness)
125
        return 0;
126

127
    return RandomGetClock();
128
}
129
#else
130
long int RandomGet(void)
131
{
132
    if (g_disable_randomness)
133
        return 0;
134

135
    return RandomGetPosix();
136
}
137
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc