Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/datasets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,11 @@ static int DatasetOpSerialized(Dataset *set, const char *string, DatasetOpFunc D

switch (set->type) {
case DATASET_TYPE_STRING: {
uint32_t decoded_size = SCBase64DecodeBufferSize(strlen(string));
if (strlen(string) > UINT16_MAX) {
// size check before cast and stack allocation
return -1;
}
uint32_t decoded_size = SCBase64DecodeBufferSize((uint32_t)strlen(string));
uint8_t decoded[decoded_size];
uint32_t num_decoded = SCBase64Decode(
(const uint8_t *)string, strlen(string), SCBase64ModeStrict, decoded);
Expand Down
23 changes: 13 additions & 10 deletions src/detect-bsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,38 @@
/*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 = 0;
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 && bsize >= 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);
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;
}
Expand Down Expand Up @@ -157,14 +158,16 @@ int DetectBsizeMatch(const SigMatchCtx *ctx, const uint64_t buffer_size, bool eo
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);
Expand Down
2 changes: 1 addition & 1 deletion src/detect-byte-extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ int DetectByteExtractDoMatch(DetectEngineThreadCtx *det_ctx, const SigMatchData

ptr += extbytes;

det_ctx->buffer_offset = ptr - payload;
det_ctx->buffer_offset = (uint32_t)(ptr - payload);

*value = val;
SCLogDebug("extracted value is %"PRIu64, val);
Expand Down
2 changes: 1 addition & 1 deletion src/detect-bytejump.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ bool DetectBytejumpDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s,

/* 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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/detect-bytemath.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ int DetectByteMathDoMatch(DetectEngineThreadCtx *det_ctx, const DetectByteMathDa
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;
Expand Down
2 changes: 1 addition & 1 deletion src/detect-bytetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ static DetectBytetestData *DetectBytetestParse(
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;
}
Expand Down
11 changes: 5 additions & 6 deletions src/detect-content.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void DetectContentFree(DetectEngineCtx *de_ctx, void *ptr)
* - 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;
Expand All @@ -428,7 +428,7 @@ void SigParseRequiredContentSize(
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;
}
Expand Down Expand Up @@ -457,12 +457,11 @@ bool DetectContentPMATCHValidateCallback(const Signature *s)
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/detect-content.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void DetectContentPropagateLimits(Signature *s);

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 */
16 changes: 9 additions & 7 deletions src/detect-dsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static bool PrefilterDsizeIsPrefilterable(const Signature *s)
* \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;
Expand All @@ -217,9 +217,11 @@ int SigParseGetMaxDsize(const Signature *s)
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);
Expand Down Expand Up @@ -293,8 +295,8 @@ int SigParseMaxRequiredDsize(const Signature *s)
SCReturnInt(-1);
}

const int dsize = SigParseGetMaxDsize(s);
if (dsize < 0) {
uint16_t dsize;
if (SigParseGetMaxDsize(s, &dsize) < 0) {
/* nothing to do */
SCReturnInt(-1);
}
Expand Down Expand Up @@ -328,8 +330,8 @@ void SigParseApplyDsizeToContent(Signature *s)
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/detect-dsize.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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);

Expand Down
2 changes: 1 addition & 1 deletion src/detect-engine-analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void SetupEngineAnalysis(DetectEngineCtx *de_ctx, bool *fp_analysis, bool *rule_
}

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);
Expand Down
2 changes: 1 addition & 1 deletion src/detect-engine-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static int DetectLoadSigFile(DetectEngineCtx *de_ctx, const char *sig_file, int
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);

Expand Down
2 changes: 1 addition & 1 deletion src/detect-engine-prefilter-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static uint32_t PrefilterPacketHeaderHashFunc(HashListTable *ht, void *data, uin
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,
Expand Down
6 changes: 3 additions & 3 deletions src/detect-engine-prefilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ static inline void QuickSortSigIntId(SigIntId *sids, uint32_t n)
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));
}

/**
Expand Down Expand Up @@ -698,7 +698,7 @@ static uint32_t PrefilterStoreHashFunc(HashListTable *ht, void *data, uint16_t d
{
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];
Expand Down
2 changes: 1 addition & 1 deletion src/detect-engine-register.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ static void PrintFeatureList(const SigTableElmt *e, char sep)
}
}

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);
Expand Down
7 changes: 5 additions & 2 deletions src/detect-flow-age.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ static int DetectFlowAgeMatch(
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)
Expand Down
4 changes: 2 additions & 2 deletions src/detect-http-cookie.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static InspectionBuffer *GetRequestData(DetectEngineThreadCtx *det_ctx,
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(
Expand All @@ -214,7 +214,7 @@ static InspectionBuffer *GetResponseData(DetectEngineThreadCtx *det_ctx,
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(
Expand Down
3 changes: 1 addition & 2 deletions src/detect-http-header-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ void HttpHeaderThreadDataFree(void *data)
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)) {
Expand Down
3 changes: 1 addition & 2 deletions src/detect-http-header-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ void HttpHeaderThreadDataFree(void *data);
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 */
4 changes: 2 additions & 2 deletions src/detect-http-headers-stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static InspectionBuffer *GetRequestData(DetectEngineThreadCtx *det_ctx,
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(
Expand Down Expand Up @@ -117,7 +117,7 @@ static InspectionBuffer *GetResponseData(DetectEngineThreadCtx *det_ctx,
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(
Expand Down
6 changes: 3 additions & 3 deletions src/detect-http-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
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(
Expand Down Expand Up @@ -357,10 +357,10 @@ static InspectionBuffer *GetRawData(DetectEngineThreadCtx *det_ctx,
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(
Expand Down
2 changes: 1 addition & 1 deletion src/detect-http-method.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
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(
Expand Down
2 changes: 1 addition & 1 deletion src/detect-http-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
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");
Expand Down
2 changes: 1 addition & 1 deletion src/detect-http-request-line.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
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(
Expand Down
2 changes: 1 addition & 1 deletion src/detect-http-response-line.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
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(
Expand Down
Loading
Loading