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

OISF / suricata / 23350122333

20 Mar 2026 03:33PM UTC coverage: 76.492% (-2.8%) from 79.315%
23350122333

Pull #15053

github

web-flow
Merge f5bf69f97 into 6587e363a
Pull Request #15053: Flow queue/v3

113 of 129 new or added lines in 9 files covered. (87.6%)

9534 existing lines in 453 files now uncovered.

256601 of 335461 relevant lines covered (76.49%)

4680806.66 hits per line

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

62.69
/src/detect-offset.c
1
/* Copyright (C) 2007-2019 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
 * \author Anoop Saldanha <anoopsaldanha@gmail.com>
23
 *
24
 * Implements the offset keyword.
25
 */
26

27
#include "suricata-common.h"
28

29
#include "decode.h"
30

31
#include "detect.h"
32
#include "detect-parse.h"
33
#include "detect-content.h"
34
#include "detect-uricontent.h"
35
#include "detect-byte.h"
36
#include "detect-byte-extract.h"
37
#include "detect-offset.h"
38

39
#include "flow-var.h"
40

41
#include "util-byte.h"
42
#include "util-debug.h"
43

44
static int DetectOffsetSetup(DetectEngineCtx *, Signature *, const char *);
45

46
void DetectOffsetRegister (void)
47
{
2,222✔
48
    sigmatch_table[DETECT_OFFSET].name = "offset";
2,222✔
49
    sigmatch_table[DETECT_OFFSET].desc = "designate from which byte in the payload will be checked to find a match";
2,222✔
50
    sigmatch_table[DETECT_OFFSET].url = "/rules/payload-keywords.html#offset";
2,222✔
51
    sigmatch_table[DETECT_OFFSET].Setup = DetectOffsetSetup;
2,222✔
52
}
2,222✔
53

54
int DetectOffsetSetup (DetectEngineCtx *de_ctx, Signature *s, const char *offsetstr)
55
{
2,355✔
56
    const char *str = offsetstr;
2,355✔
57

58
    /* retrieve the sm to apply the offset against */
59
    SigMatch *pm = SCDetectGetLastSMFromLists(s, DETECT_CONTENT, -1);
2,355✔
60
    if (pm == NULL) {
2,355✔
UNCOV
61
        SCLogError("offset needs preceding content option.");
×
UNCOV
62
        return -1;
×
UNCOV
63
    }
×
64

65
    /* verify other conditions */
66
    DetectContentData *cd = (DetectContentData *)pm->ctx;
2,355✔
67

68
    if (cd->flags & DETECT_CONTENT_STARTS_WITH) {
2,355✔
UNCOV
69
        SCLogError("can't use offset with startswith.");
×
UNCOV
70
        return -1;
×
UNCOV
71
    }
×
72
    if (cd->flags & DETECT_CONTENT_OFFSET) {
2,355✔
73
        SCLogError("can't use multiple offsets for the same content.");
1✔
74
        return -1;
1✔
75
    }
1✔
76
    if (cd->flags & (DETECT_CONTENT_WITHIN | DETECT_CONTENT_DISTANCE)) {
2,354✔
UNCOV
77
        SCLogError("can't use a relative "
×
UNCOV
78
                   "keyword like within/distance with a absolute "
×
UNCOV
79
                   "relative keyword like depth/offset for the same "
×
UNCOV
80
                   "content.");
×
UNCOV
81
        return -1;
×
UNCOV
82
    }
×
83
    if (cd->flags & DETECT_CONTENT_NEGATED && cd->flags & DETECT_CONTENT_FAST_PATTERN) {
2,354✔
84
        SCLogError("can't have a relative "
13✔
85
                   "negated keyword set along with 'fast_pattern'.");
13✔
86
        return -1;
13✔
87
    }
13✔
88
    if (cd->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) {
2,341✔
89
        SCLogError("can't have a relative "
13✔
90
                   "keyword set along with 'fast_pattern:only;'.");
13✔
91
        return -1;
13✔
92
    }
13✔
93
    if (str[0] != '-' && isalpha((unsigned char)str[0])) {
2,328✔
94
        DetectByteIndexType index;
15✔
95
        if (!DetectByteRetrieveSMVar(str, s, -1, &index)) {
15✔
UNCOV
96
            SCLogError("unknown byte_ keyword var "
×
UNCOV
97
                       "seen in offset - %s.",
×
UNCOV
98
                    str);
×
UNCOV
99
            return -1;
×
UNCOV
100
        }
×
101
        cd->offset = index;
15✔
102
        cd->flags |= DETECT_CONTENT_OFFSET_VAR;
15✔
103
    } else {
2,313✔
104
        if (StringParseUint16(&cd->offset, 0, 0, str) < 0)
2,313✔
UNCOV
105
        {
×
UNCOV
106
            SCLogError("invalid value for offset: %s.", str);
×
UNCOV
107
            return -1;
×
UNCOV
108
        }
×
109
        if (cd->depth != 0) {
2,313✔
110
            if (cd->depth < cd->content_len) {
713✔
111
                SCLogDebug("depth increased to %"PRIu32" to match pattern len",
×
112
                           cd->content_len);
×
113
                cd->depth = cd->content_len;
×
114
            }
×
115
            /* Updating the depth as is relative to the offset */
116
            cd->depth += cd->offset;
713✔
117
        }
713✔
118
    }
2,313✔
119
    cd->flags |= DETECT_CONTENT_OFFSET;
2,328✔
120
    return 0;
2,328✔
121
}
2,328✔
122

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