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

OISF / suricata / 22550902417

01 Mar 2026 07:32PM UTC coverage: 68.401% (-5.3%) from 73.687%
22550902417

Pull #14922

github

web-flow
github-actions: bump actions/upload-artifact from 6.0.0 to 7.0.0

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6.0.0 to 7.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

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

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #14922: github-actions: bump actions/upload-artifact from 6.0.0 to 7.0.0

218243 of 319063 relevant lines covered (68.4%)

3284926.58 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
197,262✔
31

32
MemBuffer *MemBufferCreateNew(uint32_t size)
33
{
197,198✔
34
    sc_errno = SC_OK;
197,198✔
35
    if (size > MAX_LIMIT) {
197,198✔
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);
197,198✔
44

45
    MemBuffer *buffer = SCCalloc(1, total_size);
197,198✔
46
    if (unlikely(buffer == NULL)) {
197,198✔
47
        sc_errno = SC_ENOMEM;
×
48
        return NULL;
×
49
    }
×
50
    buffer->size = size;
197,198✔
51
    return buffer;
197,198✔
52
}
197,198✔
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) {
64✔
61
    if (((*buffer)->size + expand_by) > MAX_LIMIT) {
64✔
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) {
64✔
70
        expand_by = expand_by - (expand_by % 4096) + 4096;
1✔
71
    }
1✔
72

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

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

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

86
void MemBufferFree(MemBuffer *buffer)
87
{
197,198✔
88
    SCFree(buffer);
197,198✔
89
}
197,198✔
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
{
6,067,121✔
117
    uint32_t write_len;
6,067,121✔
118
    if (raw_len >= dst->size - dst->offset) {
6,067,121✔
119
        SCLogDebug("Truncating data write since it exceeded buffer limit of %" PRIu32, dst->size);
×
120
        write_len = dst->size - dst->offset - 1;
×
121
    } else {
6,067,121✔
122
        write_len = raw_len;
6,067,121✔
123
    }
6,067,121✔
124
    memcpy(dst->buffer + dst->offset, raw, write_len);
6,067,121✔
125
    dst->offset += write_len;
6,067,121✔
126
    dst->buffer[dst->offset] = '\0';
6,067,121✔
127
    return write_len;
6,067,121✔
128
}
6,067,121✔
129

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