• 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

55.91
/src/util-buffer.c
1
/* Copyright (C) 2007-2023 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 Anoop Saldanha <anoopsaldanha@gmail.com>
22
 */
23

24
#include "suricata-common.h"
25
#include "suricata.h"
26
#include "util-debug.h"
27
#include "util-buffer.h"
28

29
/* 10 mb */
30
#define MAX_LIMIT 10485760
196,478✔
31

32
MemBuffer *MemBufferCreateNew(uint32_t size)
33
{
196,477✔
34
    sc_errno = SC_OK;
196,477✔
35
    if (size > MAX_LIMIT) {
196,477✔
36
        SCLogWarning("Mem buffer asked to create "
×
37
                     "buffer with size greater than API limit - %d",
×
38
                MAX_LIMIT);
×
39
        sc_errno = SC_EINVAL;
×
40
        return NULL;
×
41
    }
×
42

43
    size_t total_size = size + sizeof(MemBuffer);
196,477✔
44

45
    MemBuffer *buffer = SCCalloc(1, total_size);
196,477✔
46
    if (unlikely(buffer == NULL)) {
196,477✔
47
        sc_errno = SC_ENOMEM;
×
48
        return NULL;
×
49
    }
×
50
    buffer->size = size;
196,477✔
51
    return buffer;
196,477✔
52
}
196,477✔
53

54
/** \brief expand membuffer by size of 'expand_by'
55
 *
56
 *  If expansion failed, buffer will still be valid.
57
 *
58
 *  \retval result 0 ok, -1 expansion failed
59
 */
60
int MemBufferExpand(MemBuffer **buffer, uint32_t expand_by) {
1✔
61
    if (((*buffer)->size + expand_by) > MAX_LIMIT) {
1✔
62
        SCLogWarning("Mem buffer asked to create "
×
63
                     "buffer with size greater than API limit - %d",
×
64
                MAX_LIMIT);
×
65
        return -1;
×
66
    }
×
67

68
    /* Adjust expand_by to next multiple of 4k. */
69
    if (expand_by % 4096 != 0) {
1✔
70
        expand_by = expand_by - (expand_by % 4096) + 4096;
1✔
71
    }
1✔
72

73
    size_t total_size = (*buffer)->size + sizeof(MemBuffer) + expand_by;
1✔
74

75
    MemBuffer *tbuffer = SCRealloc(*buffer, total_size);
1✔
76
    if (unlikely(tbuffer == NULL)) {
1✔
77
        return -1;
×
78
    }
×
79
    *buffer = tbuffer;
1✔
80
    (*buffer)->size += expand_by;
1✔
81

82
    SCLogDebug("expanded buffer by %u, size is now %u", expand_by, (*buffer)->size);
1✔
83
    return 0;
1✔
84
}
1✔
85

86
void MemBufferFree(MemBuffer *buffer)
87
{
196,477✔
88
    SCFree(buffer);
196,477✔
89
}
196,477✔
90

91
void MemBufferPrintToFP(MemBuffer *buffer, FILE *fp)
92
{
×
93
    for (uint32_t i = 0; i < buffer->offset; i++) {
×
94
        if (isprint(buffer->buffer[i]))
×
95
            fprintf(fp, "%c", buffer->buffer[i]);
×
96
        else
×
97
            fprintf(fp, "|%02X|", buffer->buffer[i]);
×
98
    }
×
99
}
×
100

101
size_t MemBufferPrintToFPAsString(MemBuffer *b, FILE *fp)
102
{
×
103
    return fwrite(MEMBUFFER_BUFFER(b), sizeof(uint8_t), MEMBUFFER_OFFSET(b), fp);
×
104
}
×
105

106
void MemBufferPrintToFPAsHex(MemBuffer *b, FILE *fp)
107
{
×
108
    for (uint32_t i = 0; i < MEMBUFFER_OFFSET(b); i++) {
×
109
        if (MEMBUFFER_OFFSET(b) % 8 == 0)
×
110
            fprintf(fp, "\n");
×
111
        fprintf(fp, " %02X", b->buffer[i]);
×
112
    }
×
113
}
×
114

115
uint32_t MemBufferWriteRaw(MemBuffer *dst, const uint8_t *raw, const uint32_t raw_len)
116
{
5,740,169✔
117
    uint32_t write_len;
5,740,169✔
118
    if (raw_len >= dst->size - dst->offset) {
5,740,169✔
119
        SCLogDebug("Truncating data write since it exceeded buffer limit of %" PRIu32, dst->size);
×
120
        write_len = dst->size - dst->offset - 1;
×
121
    } else {
5,740,169✔
122
        write_len = raw_len;
5,740,169✔
123
    }
5,740,169✔
124
    memcpy(dst->buffer + dst->offset, raw, write_len);
5,740,169✔
125
    dst->offset += write_len;
5,740,169✔
126
    dst->buffer[dst->offset] = '\0';
5,740,169✔
127
    return write_len;
5,740,169✔
128
}
5,740,169✔
129

130
void MemBufferWriteString(MemBuffer *dst, const char *fmt, ...)
131
{
88,607✔
132
    uint32_t available = dst->size - dst->offset;
88,607✔
133
    uint32_t max_string_size = MIN(available, 2048);
88,607✔
134
    va_list ap;
88,607✔
135
    char string[max_string_size];
88,607✔
136
    va_start(ap, fmt);
88,607✔
137
    int written = vsnprintf(string, sizeof(string), fmt, ap);
88,607✔
138
    va_end(ap);
88,607✔
139
    if (written < 0) {
88,607✔
140
        return;
×
141
    } else if ((uint32_t)written > max_string_size) {
88,607✔
142
        SCLogDebug("Truncating data write since it exceeded buffer "
×
143
                   "limit of %" PRIu32,
×
144
                dst->size);
×
145
    }
×
146
    size_t string_size = strlen(string);
88,607✔
147
    memcpy(dst->buffer + dst->offset, string, string_size);
88,607✔
148
    dst->offset += string_size;
88,607✔
149
    dst->buffer[dst->offset] = '\0';
88,607✔
150
}
88,607✔
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