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

OISF / suricata / 23352517976

20 Mar 2026 04:32PM UTC coverage: 65.866% (-13.4%) from 79.315%
23352517976

Pull #15072

github

web-flow
Merge abcd1935f into 6587e363a
Pull Request #15072: Stack 8001 v16.3

41 of 70 new or added lines in 10 files covered. (58.57%)

18894 existing lines in 577 files now uncovered.

143735 of 218225 relevant lines covered (65.87%)

4342818.61 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,212✔
48
    sigmatch_table[DETECT_OFFSET].name = "offset";
2,212✔
49
    sigmatch_table[DETECT_OFFSET].desc = "designate from which byte in the payload will be checked to find a match";
2,212✔
50
    sigmatch_table[DETECT_OFFSET].url = "/rules/payload-keywords.html#offset";
2,212✔
51
    sigmatch_table[DETECT_OFFSET].Setup = DetectOffsetSetup;
2,212✔
52
}
2,212✔
53

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

58
    /* retrieve the sm to apply the offset against */
59
    SigMatch *pm = SCDetectGetLastSMFromLists(s, DETECT_CONTENT, -1);
1,096✔
60
    if (pm == NULL) {
1,096✔
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;
1,096✔
67

68
    if (cd->flags & DETECT_CONTENT_STARTS_WITH) {
1,096✔
UNCOV
69
        SCLogError("can't use offset with startswith.");
×
UNCOV
70
        return -1;
×
UNCOV
71
    }
×
72
    if (cd->flags & DETECT_CONTENT_OFFSET) {
1,096✔
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)) {
1,095✔
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) {
1,095✔
84
        SCLogError("can't have a relative "
1✔
85
                   "negated keyword set along with 'fast_pattern'.");
1✔
86
        return -1;
1✔
87
    }
1✔
88
    if (cd->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) {
1,094✔
89
        SCLogError("can't have a relative "
1✔
90
                   "keyword set along with 'fast_pattern:only;'.");
1✔
91
        return -1;
1✔
92
    }
1✔
93
    if (str[0] != '-' && isalpha((unsigned char)str[0])) {
1,093✔
94
        DetectByteIndexType index;
11✔
95
        if (!DetectByteRetrieveSMVar(str, s, -1, &index)) {
11✔
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;
11✔
102
        cd->flags |= DETECT_CONTENT_OFFSET_VAR;
11✔
103
    } else {
1,082✔
104
        if (StringParseUint16(&cd->offset, 0, 0, str) < 0)
1,082✔
UNCOV
105
        {
×
UNCOV
106
            SCLogError("invalid value for offset: %s.", str);
×
UNCOV
107
            return -1;
×
UNCOV
108
        }
×
109
        if (cd->depth != 0) {
1,082✔
110
            if (cd->depth < cd->content_len) {
352✔
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;
352✔
117
        }
352✔
118
    }
1,082✔
119
    cd->flags |= DETECT_CONTENT_OFFSET;
1,093✔
120
    return 0;
1,093✔
121
}
1,093✔
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