/*prototypes*/
static int DetectBsizeSetup (DetectEngineCtx *, Signature *, const char *);
static void DetectBsizeFree (DetectEngineCtx *, void *);
-static int SigParseGetMaxBsize(const DetectU64Data *bsz);
+static int SigParseGetMaxBsize(const DetectU64Data *bsz, uint64_t *bsize);
#ifdef UNITTESTS
static void DetectBsizeRegisterTests (void);
#endif
bool DetectBsizeValidateContentCallback(Signature *s, const SignatureInitDataBuffer *b)
{
- int bsize = -1;
+ uint64_t bsize;
+ int retval = -1;
const DetectU64Data *bsz;
for (const SigMatch *sm = b->head; sm != NULL; sm = sm->next) {
if (sm->type == DETECT_BSIZE) {
bsz = (const DetectU64Data *)sm->ctx;
- bsize = SigParseGetMaxBsize(bsz);
+ retval = SigParseGetMaxBsize(bsz, &bsize);
break;
}
}
- if (bsize == -1) {
+ if (retval == -1) {
return true;
}
uint64_t needed;
- if (bsize >= 0) {
+ if (retval == 0) {
int len, offset;
SigParseRequiredContentSize(s, bsize, b->head, &len, &offset);
- SCLogDebug("bsize: %d; len: %d; offset: %d [%s]", bsize, len, offset, s->sig_str);
+ SCLogDebug("bsize: %" PRIu64 "; len: %d; offset: %d [%s]", bsize, len, offset, s->sig_str);
needed = len;
- if (len > bsize) {
+ if ((uint64_t)len > bsize) {
goto value_error;
}
- if ((len + offset) > bsize) {
+ if ((uint64_t)(len + offset) > bsize) {
needed += offset;
goto value_error;
}
return 0;
}
-static int SigParseGetMaxBsize(const DetectU64Data *bsz)
+static int SigParseGetMaxBsize(const DetectU64Data *bsz, uint64_t *bsize)
{
switch (bsz->mode) {
case DETECT_UINT_LT:
case DETECT_UINT_EQ:
- return bsz->arg1;
+ *bsize = bsz->arg1;
+ SCReturnInt(0);
case DETECT_UINT_RA:
- return bsz->arg2;
+ *bsize = bsz->arg2;
+ SCReturnInt(0);
case DETECT_UINT_GT:
default:
SCReturnInt(-2);
ptr += extbytes;
- det_ctx->buffer_offset = ptr - payload;
+ det_ctx->buffer_offset = (uint32_t)(ptr - payload);
*value = val;
SCLogDebug("extracted value is %"PRIu64, val);
/* Adjust the detection context to the jump location. */
DEBUG_VALIDATE_BUG_ON(jumpptr < payload);
- det_ctx->buffer_offset = jumpptr - payload;
+ det_ctx->buffer_offset = (uint32_t)(jumpptr - payload);
SCReturnBool(true);
}
break;
}
- det_ctx->buffer_offset = ptr - payload;
+ det_ctx->buffer_offset = (uint32_t)(ptr - payload);
if (data->flags & DETECT_BYTEMATH_FLAG_BITMASK) {
val &= data->bitmask_val;
data->neg_op = true;
op_ptr = &args[1][1];
while (isspace((char)*op_ptr) || (*op_ptr == ',')) op_ptr++;
- op_offset = op_ptr - &args[1][0];
+ op_offset = (uint32_t)(op_ptr - &args[1][0]);
} else {
data->neg_op = false;
}
* - Negated content values are checked but not accumulated for the required size.
*/
void SigParseRequiredContentSize(
- const Signature *s, const int max_size, const SigMatch *sm, int *len, int *offset)
+ const Signature *s, const uint64_t max_size, const SigMatch *sm, int *len, int *offset)
{
int max_offset = 0, total_len = 0;
bool first = true;
if (cd->flags & DETECT_CONTENT_NEGATED) {
/* Check if distance/within cause max to be exceeded */
int check = total_len + cd->distance + cd->within;
- if (max_size < check) {
+ if (max_size < (uint64_t)check) {
*len = check;
return;
}
return true;
}
- int max_right_edge_i = SigParseGetMaxDsize(s);
- if (max_right_edge_i < 0) {
+ uint16_t max_right_edge_i;
+ if (SigParseGetMaxDsize(s, &max_right_edge_i) < 0) {
return true;
}
-
- uint32_t max_right_edge = (uint32_t)max_right_edge_i;
+ uint32_t max_right_edge = max_right_edge_i;
int min_dsize_required = SigParseMaxRequiredDsize(s);
if (min_dsize_required >= 0) {
void DetectContentPatternPrettyPrint(const DetectContentData *cd, char *str, size_t str_len);
void SigParseRequiredContentSize(
- const Signature *s, const int max, const SigMatch *sm, int *len, int *offset);
+ const Signature *s, const uint64_t max, const SigMatch *sm, int *len, int *offset);
int DetectContentConvertToNocase(DetectEngineCtx *de_ctx, DetectContentData *cd);
#endif /* SURICATA_DETECT_CONTENT_H */
* \param s signature to get dsize value from
* \retval depth or negative value
*/
-int SigParseGetMaxDsize(const Signature *s)
+int SigParseGetMaxDsize(const Signature *s, uint16_t *dsize)
{
if (s->flags & SIG_FLAG_DSIZE && s->init_data->dsize_sm != NULL) {
const DetectU16Data *dd = (const DetectU16Data *)s->init_data->dsize_sm->ctx;
case DETECT_UINT_LT:
case DETECT_UINT_EQ:
case DETECT_UINT_NE:
- return dd->arg1;
+ *dsize = dd->arg1;
+ SCReturnInt(0);
case DETECT_UINT_RA:
- return dd->arg2;
+ *dsize = dd->arg2;
+ SCReturnInt(0);
case DETECT_UINT_GT:
default:
SCReturnInt(-2);
SCReturnInt(-1);
}
- const int dsize = SigParseGetMaxDsize(s);
- if (dsize < 0) {
+ uint16_t dsize;
+ if (SigParseGetMaxDsize(s, &dsize) < 0) {
/* nothing to do */
SCReturnInt(-1);
}
if (s->flags & SIG_FLAG_DSIZE) {
SigParseSetDsizePair(s);
- int dsize = SigParseGetMaxDsize(s);
- if (dsize < 0) {
+ uint16_t dsize;
+ if (SigParseGetMaxDsize(s, &dsize) < 0) {
/* nothing to do */
return;
}
void DetectDsizeRegister (void);
int SigParseMaxRequiredDsize(const Signature *s);
-int SigParseGetMaxDsize(const Signature *s);
+int SigParseGetMaxDsize(const Signature *s, uint16_t *dsize);
void SigParseSetDsizePair(Signature *s);
void SigParseApplyDsizeToContent(Signature *s);
}
ea->file_prefix = NULL;
- int cfg_prefix_len = strlen(de_ctx->config_prefix);
+ size_t cfg_prefix_len = strlen(de_ctx->config_prefix);
if (cfg_prefix_len > 0) {
/* length of prefix + NULL + "." */
ea->file_prefix = SCCalloc(1, cfg_prefix_len + 1 + 1);
return -1;
}
- while(fgets(line + offset, (int)sizeof(line) - offset, fp) != NULL) {
+ while (fgets(line + offset, (int)(sizeof(line) - offset), fp) != NULL) {
lineno++;
size_t len = strlen(line);
PrefilterPacketHeaderCtx *ctx = data;
uint64_t hash = ctx->v1.u64[0] + ctx->v1.u64[1] + ctx->type + ctx->value;
hash %= ht->array_size;
- return hash;
+ return (uint32_t)hash;
}
static char PrefilterPacketHeaderCompareFunc(void *data1, uint16_t len1,
r--;
}
}
- QuickSortSigIntId(sids, r - sids + 1);
- QuickSortSigIntId(l, sids + n - l);
+ QuickSortSigIntId(sids, (uint32_t)(r - sids) + 1);
+ QuickSortSigIntId(l, (uint32_t)(sids + n - l));
}
/**
{
PrefilterStore *ctx = data;
- uint32_t hash = strlen(ctx->name);
+ uint32_t hash = (uint32_t)strlen(ctx->name);
for (size_t u = 0; u < strlen(ctx->name); u++) {
hash += ctx->name[u];
}
}
-static void SigMultilinePrint(int i, const char *prefix)
+static void SigMultilinePrint(size_t i, const char *prefix)
{
if (sigmatch_table[i].desc) {
printf("%sDescription: %s\n", prefix, sigmatch_table[i].desc);
if (p->flow == NULL) {
return 0;
}
- uint32_t age = SCTIME_SECS(p->flow->lastts) - SCTIME_SECS(p->flow->startts);
+ uint64_t age = SCTIME_SECS(p->flow->lastts) - SCTIME_SECS(p->flow->startts);
+ if (age > UINT32_MAX) {
+ age = UINT32_MAX;
+ }
const DetectU32Data *du32 = (const DetectU32Data *)ctx;
- return DetectU32Match(age, du32);
+ return DetectU32Match((uint32_t)age, du32);
}
static void DetectFlowAgeFree(DetectEngineCtx *de_ctx, void *ptr)
return NULL;
}
- const uint32_t data_len = htp_header_value_len(h);
+ const uint32_t data_len = (uint32_t)htp_header_value_len(h);
const uint8_t *data = htp_header_value_ptr(h);
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = htp_header_value_len(h);
+ const uint32_t data_len = (uint32_t)htp_header_value_len(h);
const uint8_t *data = htp_header_value_ptr(h);
InspectionBufferSetupAndApplyTransforms(
SCFree(hdrnames);
}
-int HttpHeaderExpandBuffer(HttpHeaderThreadData *td,
- HttpHeaderBuffer *buf, uint32_t size)
+int HttpHeaderExpandBuffer(HttpHeaderThreadData *td, HttpHeaderBuffer *buf, size_t size)
{
size_t extra = td->size_step;
while ((buf->size + extra) < (size + buf->len)) {
HttpHeaderBuffer *HttpHeaderGetBufferSpace(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags,
const int keyword_id, HttpHeaderThreadData **ret_hdr_td);
-int HttpHeaderExpandBuffer(HttpHeaderThreadData *td,
- HttpHeaderBuffer *buf, uint32_t size);
+int HttpHeaderExpandBuffer(HttpHeaderThreadData *td, HttpHeaderBuffer *buf, size_t size);
#endif /* SURICATA_DETECT_HTTP_HEADER_COMMON_H */
return NULL;
}
- const uint32_t data_len = htp_header_value_len(h);
+ const uint32_t data_len = (uint32_t)htp_header_value_len(h);
const uint8_t *data = htp_header_value_ptr(h);
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = htp_header_value_len(h);
+ const uint32_t data_len = (uint32_t)htp_header_value_len(h);
const uint8_t *data = htp_header_value_ptr(h);
InspectionBufferSetupAndApplyTransforms(
if (htp_tx_request_hostname(tx) == NULL)
return NULL;
- const uint32_t data_len = bstr_len(htp_tx_request_hostname(tx));
+ const uint32_t data_len = (uint32_t)bstr_len(htp_tx_request_hostname(tx));
const uint8_t *data = bstr_ptr(htp_tx_request_hostname(tx));
InspectionBufferSetupAndApplyTransforms(
return NULL;
data = htp_header_value_ptr(h);
- data_len = htp_header_value_len(h);
+ data_len = (uint32_t)htp_header_value_len(h);
} else {
data = (const uint8_t *)bstr_ptr(htp_uri_hostname(htp_tx_parsed_uri(tx)));
- data_len = bstr_len(htp_uri_hostname(htp_tx_parsed_uri(tx)));
+ data_len = (uint32_t)bstr_len(htp_uri_hostname(htp_tx_parsed_uri(tx)));
}
InspectionBufferSetupAndApplyTransforms(
if (htp_tx_request_method(tx) == NULL)
return NULL;
- const uint32_t data_len = bstr_len(htp_tx_request_method(tx));
+ const uint32_t data_len = (uint32_t)bstr_len(htp_tx_request_method(tx));
const uint8_t *data = bstr_ptr(htp_tx_request_method(tx));
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- uint32_t data_len = bstr_size(str);
+ uint32_t data_len = (uint32_t)bstr_size(str);
uint8_t *data = bstr_ptr(str);
if (data == NULL || data_len == 0) {
SCLogDebug("HTTP protocol not present");
if (unlikely(htp_tx_request_line(tx) == NULL)) {
return NULL;
}
- const uint32_t data_len = bstr_len(htp_tx_request_line(tx));
+ const uint32_t data_len = (uint32_t)bstr_len(htp_tx_request_line(tx));
const uint8_t *data = bstr_ptr(htp_tx_request_line(tx));
InspectionBufferSetupAndApplyTransforms(
if (unlikely(htp_tx_response_line(tx) == NULL)) {
return NULL;
}
- const uint32_t data_len = bstr_len(htp_tx_response_line(tx));
+ const uint32_t data_len = (uint32_t)bstr_len(htp_tx_response_line(tx));
const uint8_t *data = bstr_ptr(htp_tx_response_line(tx));
InspectionBufferSetupAndApplyTransforms(
if (htp_tx_response_status(tx) == NULL)
return NULL;
- const uint32_t data_len = bstr_len(htp_tx_response_status(tx));
+ const uint32_t data_len = (uint32_t)bstr_len(htp_tx_response_status(tx));
const uint8_t *data = bstr_ptr(htp_tx_response_status(tx));
InspectionBufferSetupAndApplyTransforms(
if (htp_tx_response_message(tx) == NULL)
return NULL;
- const uint32_t data_len = bstr_len(htp_tx_response_message(tx));
+ const uint32_t data_len = (uint32_t)bstr_len(htp_tx_response_message(tx));
const uint8_t *data = bstr_ptr(htp_tx_response_message(tx));
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = htp_header_value_len(h);
+ const uint32_t data_len = (uint32_t)htp_header_value_len(h);
const uint8_t *data = htp_header_value_ptr(h);
InspectionBufferSetupAndApplyTransforms(
if (request_uri_normalized == NULL)
return NULL;
- const uint32_t data_len = bstr_len(request_uri_normalized);
+ const uint32_t data_len = (uint32_t)bstr_len(request_uri_normalized);
const uint8_t *data = bstr_ptr(request_uri_normalized);
InspectionBufferSetupAndApplyTransforms(
if (unlikely(htp_tx_request_uri(tx) == NULL)) {
return NULL;
}
- const uint32_t data_len = bstr_len(htp_tx_request_uri(tx));
+ const uint32_t data_len = (uint32_t)bstr_len(htp_tx_request_uri(tx));
const uint8_t *data = bstr_ptr(htp_tx_request_uri(tx));
InspectionBufferSetupAndApplyTransforms(
pcre_match_limit = SC_MATCH_LIMIT_DEFAULT;
SCLogDebug("Using PCRE match-limit setting of: %i", pcre_match_limit);
} else {
- pcre_match_limit = val;
+ pcre_match_limit = (int)val;
if (pcre_match_limit != SC_MATCH_LIMIT_DEFAULT) {
SCLogInfo("Using PCRE match-limit setting of: %i", pcre_match_limit);
} else {
pcre_match_limit_recursion = SC_MATCH_LIMIT_RECURSION_DEFAULT;
SCLogDebug("Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion);
} else {
- pcre_match_limit_recursion = val;
+ pcre_match_limit_recursion = (int)val;
if (pcre_match_limit_recursion != SC_MATCH_LIMIT_RECURSION_DEFAULT) {
SCLogInfo("Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion);
} else {
int start_offset = 0;
if (det_ctx->pcre_match_start_offset != 0) {
- start_offset = (payload + det_ctx->pcre_match_start_offset - ptr);
+ start_offset = (uint32_t)(payload - ptr) + det_ctx->pcre_match_start_offset;
}
/* run the actual pcre detection */
PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
/* update offset for pcre RELATIVE */
- det_ctx->buffer_offset = (ptr + ov[1]) - payload;
- det_ctx->pcre_match_start_offset = (ptr + ov[0] + 1) - payload;
+ det_ctx->buffer_offset = (uint32_t)((ptr + ov[1]) - payload);
+ det_ctx->pcre_match_start_offset = (uint32_t)((ptr + ov[0] + 1) - payload);
ret = 1;
}
SCLogDebug("regexstr %s", regexstr);
if (fcap && !pcap)
- cut_capture = fcap - regexstr;
+ cut_capture = (int)(fcap - regexstr);
else if (pcap && !fcap)
- cut_capture = pcap - regexstr;
+ cut_capture = (int)(pcap - regexstr);
else {
BUG_ON(pcap == NULL); // added to assist cppcheck
BUG_ON(fcap == NULL);
- cut_capture = MIN((pcap - regexstr), (fcap - regexstr));
+ cut_capture = (int)MIN((pcap - regexstr), (fcap - regexstr));
}
SCLogDebug("cut_capture %d", cut_capture);
pcre2_match_data_free(match);
char *endptr = NULL;
- long prio = strtol(copy_str, &endptr, 10);
+ int prio = (int)strtol(copy_str, &endptr, 10);
if (endptr == NULL || *endptr != '\0') {
SCLogError("Saw an invalid character as arg "
"to priority keyword");
goto error;
}
- int ref_len = strlen(uri);
+ size_t ref_len = strlen(uri);
/* no key, reference -- return an error */
if (strlen(key) == 0 || ref_len == 0)
goto error;
return NULL;
}
- const uint32_t data_len = strlen(connp->cert0_fingerprint);
+ const uint32_t data_len = (uint32_t)strlen(connp->cert0_fingerprint);
const uint8_t *data = (uint8_t *)connp->cert0_fingerprint;
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = strlen(connp->cert0_issuerdn);
+ const uint32_t data_len = (uint32_t)strlen(connp->cert0_issuerdn);
const uint8_t *data = (uint8_t *)connp->cert0_issuerdn;
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = strlen(connp->cert0_serial);
+ const uint32_t data_len = (uint32_t)strlen(connp->cert0_serial);
const uint8_t *data = (uint8_t *)connp->cert0_serial;
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = strlen(connp->cert0_subject);
+ const uint32_t data_len = (uint32_t)strlen(connp->cert0_subject);
const uint8_t *data = (uint8_t *)connp->cert0_subject;
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = strlen(ssl_state->client_connp.ja3_hash);
+ const uint32_t data_len = (uint32_t)strlen(ssl_state->client_connp.ja3_hash);
const uint8_t *data = (uint8_t *)ssl_state->client_connp.ja3_hash;
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = strlen(ssl_state->client_connp.ja3_str->data);
+ const uint32_t data_len = (uint32_t)strlen(ssl_state->client_connp.ja3_str->data);
const uint8_t *data = (uint8_t *)ssl_state->client_connp.ja3_str->data;
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = strlen(ssl_state->server_connp.ja3_hash);
+ const uint32_t data_len = (uint32_t)strlen(ssl_state->server_connp.ja3_hash);
const uint8_t *data = (uint8_t *)ssl_state->server_connp.ja3_hash;
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = strlen(ssl_state->server_connp.ja3_str->data);
+ const uint32_t data_len = (uint32_t)strlen(ssl_state->server_connp.ja3_str->data);
const uint8_t *data = (uint8_t *)ssl_state->server_connp.ja3_str->data;
InspectionBufferSetupAndApplyTransforms(
return NULL;
}
- const uint32_t data_len = strlen(ssl_state->client_connp.sni);
+ const uint32_t data_len = (uint32_t)strlen(ssl_state->client_connp.sni);
const uint8_t *data = (uint8_t *)ssl_state->client_connp.sni;
InspectionBufferSetupAndApplyTransforms(
}
*buf = (const uint8_t *)connp->cert0_sans[idx];
- *buf_len = strlen(connp->cert0_sans[idx]);
+ *buf_len = (uint32_t)strlen(connp->cert0_sans[idx]);
return true;
}
}
}
- det_ctx->match_array_cnt = match_array - det_ctx->match_array;
+ det_ctx->match_array_cnt = (uint32_t)(match_array - det_ctx->match_array);
DEBUG_VALIDATE_BUG_ON(det_ctx->pmq.rule_id_array_cnt < det_ctx->match_array_cnt);
PMQ_RESET(&det_ctx->pmq);
}