Skip to content
Merged
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
22 changes: 4 additions & 18 deletions rust/src/ldap/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl<'a> From<ldap_parser::ldap::LdapMessage<'a>> for LdapMessage {
ldap_parser::ldap::ProtocolOp::IntermediateResponse(msg) => {
Self::from_intermediate_response(msg)
}
_ => ProtocolOp::Unknown,
ldap_parser::ldap::ProtocolOp::AbandonRequest(_) => ProtocolOp::Unknown,
};
let controls = ldap_msg.controls.map(|ctls| {
ctls.iter()
Expand Down Expand Up @@ -414,6 +414,7 @@ impl LdapMessage {
| ProtocolOp::DelRequest(_)
| ProtocolOp::ModDnRequest(_)
| ProtocolOp::CompareRequest(_)
| ProtocolOp::Unknown // AbandonRequest
| ProtocolOp::ExtendedRequest(_) => {
return true;
}
Expand All @@ -424,23 +425,8 @@ impl LdapMessage {
}

pub fn is_response(&self) -> bool {
match self.protocol_op {
ProtocolOp::BindResponse(_)
| ProtocolOp::SearchResultEntry(_)
| ProtocolOp::SearchResultReference(_)
| ProtocolOp::SearchResultDone(_)
| ProtocolOp::ModifyResponse(_)
| ProtocolOp::AddResponse(_)
| ProtocolOp::DelResponse(_)
| ProtocolOp::ModDnResponse(_)
| ProtocolOp::CompareResponse(_)
| ProtocolOp::ExtendedResponse(_) => {
return true;
}
_ => {
return false;
}
}
// it is either a response or a request
return !self.is_request();
}

fn from_bind_request(msg: ldap_parser::ldap::BindRequest) -> ProtocolOp {
Expand Down
19 changes: 19 additions & 0 deletions src/detect-content.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,25 @@ void SigParseRequiredContentSize(
*/
bool DetectContentPMATCHValidateCallback(const Signature *s)
{
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
bool has_pcre = false;
bool has_content = false;
for (SigMatch *sm = s->init_data->smlists[DETECT_SM_LIST_PMATCH]; sm != NULL; sm = sm->next) {
if (sm->type == DETECT_PCRE) {
has_pcre = true;
} else if (sm->type == DETECT_CONTENT) {
has_content = true;
break;
}
}
if (has_pcre && !has_content) {
// Fuzzing does not allow rules with pcre and without content on payload
// as it is known to be a bad rule for performance causing possible timeouts
// Engine analysis has more generic warn_pcre_no_content about this
return false;
}
#endif

if (!(s->flags & SIG_FLAG_DSIZE)) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/output-json-alert.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,8 @@ static bool AlertJsonStreamData(const AlertJsonOutputCtx *json_output_ctx, JsonA
if (json_output_ctx->flags & LOG_JSON_PAYLOAD) {
uint8_t printable_buf[cbd.payload->offset + 1];
uint32_t offset = 0;
PrintStringsToBuffer(printable_buf, &offset, sizeof(printable_buf), cbd.payload->buffer,
cbd.payload->offset);
PrintStringsToBuffer(printable_buf, &offset, cbd.payload->offset + 1,
cbd.payload->buffer, cbd.payload->offset);
jb_set_string(jb, "payload_printable", (char *)printable_buf);
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/output-json-email-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ TmEcode EveEmailLogJson(JsonEmailLogThread *aft, JsonBuilder *js, const Packet *
SCReturnInt(TM_ECODE_OK);
}

bool EveEmailAddMetadata(const Flow *f, uint32_t tx_id, JsonBuilder *js)
bool EveEmailAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
{
SMTPState *smtp_state = (SMTPState *)FlowGetAppState(f);
if (smtp_state) {
Expand Down
2 changes: 1 addition & 1 deletion src/output-json-email-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct JsonEmailLogThread_ {
} JsonEmailLogThread;

TmEcode EveEmailLogJson(JsonEmailLogThread *aft, JsonBuilder *js, const Packet *p, Flow *f, void *state, void *vtx, uint64_t tx_id);
bool EveEmailAddMetadata(const Flow *f, uint32_t tx_id, JsonBuilder *js);
bool EveEmailAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js);

void OutputEmailInitConf(ConfNode *conf, OutputJsonEmailCtx *email_ctx);

Expand Down
2 changes: 1 addition & 1 deletion src/output-json-flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static void EveFlowLogJSON(OutputJsonThreadCtx *aft, JsonBuilder *jb, Flow *f)
CreateIsoTimeString(f->lastts, timebuf2, sizeof(timebuf2));
jb_set_string(jb, "end", timebuf2);

int32_t age = SCTIME_SECS(f->lastts) - SCTIME_SECS(f->startts);
uint64_t age = (SCTIME_SECS(f->lastts) - SCTIME_SECS(f->startts));
jb_set_uint(jb, "age", age);

if (f->flow_end_flags & FLOW_END_FLAG_EMERGENCY)
Expand Down
6 changes: 3 additions & 3 deletions src/output-json-frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static void FrameAddPayloadTCP(Flow *f, const TcpSession *ssn, const TcpStream *
jb_set_base64(jb, "payload", cbd.payload->buffer, cbd.payload->offset);
uint8_t printable_buf[cbd.payload->offset + 1];
uint32_t offset = 0;
PrintStringsToBuffer(printable_buf, &offset, sizeof(printable_buf), cbd.payload->buffer,
PrintStringsToBuffer(printable_buf, &offset, cbd.payload->offset + 1, cbd.payload->buffer,
cbd.payload->offset);
jb_set_string(jb, "payload_printable", (char *)printable_buf);
jb_set_bool(jb, "complete", complete);
Expand All @@ -217,12 +217,12 @@ static void FrameAddPayloadUDP(JsonBuilder *js, const Packet *p, const Frame *fr

uint32_t frame_len;
if (frame->len == -1) {
frame_len = p->payload_len - frame->offset;
frame_len = (uint32_t)(p->payload_len - frame->offset);
} else {
frame_len = (uint32_t)frame->len;
}
if (frame->offset + frame_len > p->payload_len) {
frame_len = p->payload_len - frame->offset;
frame_len = (uint32_t)(p->payload_len - frame->offset);
JB_SET_FALSE(js, "complete");
} else {
JB_SET_TRUE(js, "complete");
Expand Down
31 changes: 15 additions & 16 deletions src/output-json-http.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ static void EveHttpLogJSONBasic(JsonBuilder *js, htp_tx_t *tx)
{
/* hostname */
if (tx->request_hostname != NULL) {
jb_set_string_from_bytes(
js, "hostname", bstr_ptr(tx->request_hostname), bstr_len(tx->request_hostname));
jb_set_string_from_bytes(js, "hostname", bstr_ptr(tx->request_hostname),
(uint32_t)bstr_len(tx->request_hostname));
}

/* port */
Expand All @@ -214,22 +214,23 @@ static void EveHttpLogJSONBasic(JsonBuilder *js, htp_tx_t *tx)

/* uri */
if (tx->request_uri != NULL) {
jb_set_string_from_bytes(js, "url", bstr_ptr(tx->request_uri), bstr_len(tx->request_uri));
jb_set_string_from_bytes(
js, "url", bstr_ptr(tx->request_uri), (uint32_t)bstr_len(tx->request_uri));
}

if (tx->request_headers != NULL) {
/* user agent */
htp_header_t *h_user_agent = htp_table_get_c(tx->request_headers, "user-agent");
if (h_user_agent != NULL) {
jb_set_string_from_bytes(js, "http_user_agent", bstr_ptr(h_user_agent->value),
bstr_len(h_user_agent->value));
(uint32_t)bstr_len(h_user_agent->value));
}

/* x-forwarded-for */
htp_header_t *h_x_forwarded_for = htp_table_get_c(tx->request_headers, "x-forwarded-for");
if (h_x_forwarded_for != NULL) {
jb_set_string_from_bytes(js, "xff", bstr_ptr(h_x_forwarded_for->value),
bstr_len(h_x_forwarded_for->value));
(uint32_t)bstr_len(h_x_forwarded_for->value));
}
}

Expand All @@ -248,8 +249,8 @@ static void EveHttpLogJSONBasic(JsonBuilder *js, htp_tx_t *tx)
htp_header_t *h_content_range = htp_table_get_c(tx->response_headers, "content-range");
if (h_content_range != NULL) {
jb_open_object(js, "content_range");
jb_set_string_from_bytes(
js, "raw", bstr_ptr(h_content_range->value), bstr_len(h_content_range->value));
jb_set_string_from_bytes(js, "raw", bstr_ptr(h_content_range->value),
(uint32_t)bstr_len(h_content_range->value));
HTTPContentRange crparsed;
if (HTPParseContentRange(h_content_range->value, &crparsed) == 0) {
if (crparsed.start >= 0)
Expand All @@ -273,19 +274,19 @@ static void EveHttpLogJSONExtended(JsonBuilder *js, htp_tx_t *tx)
}
if (h_referer != NULL) {
jb_set_string_from_bytes(
js, "http_refer", bstr_ptr(h_referer->value), bstr_len(h_referer->value));
js, "http_refer", bstr_ptr(h_referer->value), (uint32_t)bstr_len(h_referer->value));
}

/* method */
if (tx->request_method != NULL) {
jb_set_string_from_bytes(
js, "http_method", bstr_ptr(tx->request_method), bstr_len(tx->request_method));
jb_set_string_from_bytes(js, "http_method", bstr_ptr(tx->request_method),
(uint32_t)bstr_len(tx->request_method));
}

/* protocol */
if (tx->request_protocol != NULL) {
jb_set_string_from_bytes(
js, "protocol", bstr_ptr(tx->request_protocol), bstr_len(tx->request_protocol));
jb_set_string_from_bytes(js, "protocol", bstr_ptr(tx->request_protocol),
(uint32_t)bstr_len(tx->request_protocol));
}

/* response status: from libhtp:
Expand All @@ -306,7 +307,7 @@ static void EveHttpLogJSONExtended(JsonBuilder *js, htp_tx_t *tx)
htp_header_t *h_location = htp_table_get_c(tx->response_headers, "location");
if (h_location != NULL) {
jb_set_string_from_bytes(
js, "redirect", bstr_ptr(h_location->value), bstr_len(h_location->value));
js, "redirect", bstr_ptr(h_location->value), (uint32_t)bstr_len(h_location->value));
}

/* length */
Expand Down Expand Up @@ -383,9 +384,7 @@ static void BodyPrintableBuffer(JsonBuilder *js, HtpBody *body, const char *key)
}

uint8_t printable_buf[body_data_len + 1];
PrintStringsToBuffer(printable_buf, &offset,
sizeof(printable_buf),
body_data, body_data_len);
PrintStringsToBuffer(printable_buf, &offset, body_data_len + 1, body_data, body_data_len);
if (offset > 0) {
jb_set_string(js, key, (char *)printable_buf);
}
Expand Down
4 changes: 2 additions & 2 deletions src/output-json-netflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static void NetFlowLogEveToServer(JsonBuilder *js, Flow *f)
jb_set_string(js, "start", timebuf1);
jb_set_string(js, "end", timebuf2);

int32_t age = SCTIME_SECS(f->lastts) - SCTIME_SECS(f->startts);
uint64_t age = (SCTIME_SECS(f->lastts) - SCTIME_SECS(f->startts));
jb_set_uint(js, "age", age);

jb_set_uint(js, "min_ttl", f->min_ttl_toserver);
Expand Down Expand Up @@ -237,7 +237,7 @@ static void NetFlowLogEveToClient(JsonBuilder *js, Flow *f)
jb_set_string(js, "start", timebuf1);
jb_set_string(js, "end", timebuf2);

int32_t age = SCTIME_SECS(f->lastts) - SCTIME_SECS(f->startts);
uint64_t age = (SCTIME_SECS(f->lastts) - SCTIME_SECS(f->startts));
jb_set_uint(js, "age", age);

/* To client is zero if we did not see any packet */
Expand Down
40 changes: 16 additions & 24 deletions src/output-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,18 @@ static void EveAddPacketVars(const Packet *p, JsonBuilder *js_vars)
if (pv->key != NULL) {
uint32_t offset = 0;
uint8_t keybuf[pv->key_len + 1];
PrintStringsToBuffer(keybuf, &offset,
sizeof(keybuf),
pv->key, pv->key_len);
PrintStringsToBuffer(keybuf, &offset, pv->key_len + 1, pv->key, pv->key_len);
uint32_t len = pv->value_len;
uint8_t printable_buf[len + 1];
offset = 0;
PrintStringsToBuffer(printable_buf, &offset,
sizeof(printable_buf),
pv->value, pv->value_len);
PrintStringsToBuffer(printable_buf, &offset, len + 1, pv->value, pv->value_len);
jb_set_string(js_vars, (char *)keybuf, (char *)printable_buf);
} else {
const char *varname = VarNameStoreLookupById(pv->id, VAR_TYPE_PKT_VAR);
uint32_t len = pv->value_len;
uint8_t printable_buf[len + 1];
uint32_t offset = 0;
PrintStringsToBuffer(printable_buf, &offset,
sizeof(printable_buf),
pv->value, pv->value_len);
PrintStringsToBuffer(printable_buf, &offset, len + 1, pv->value, pv->value_len);
jb_set_string(js_vars, varname, (char *)printable_buf);
}
jb_close(js_vars);
Expand Down Expand Up @@ -271,9 +265,8 @@ static void EveAddFlowVars(const Flow *f, JsonBuilder *js_root, JsonBuilder **js
uint32_t len = fv->data.fv_str.value_len;
uint8_t printable_buf[len + 1];
uint32_t offset = 0;
PrintStringsToBuffer(printable_buf, &offset,
sizeof(printable_buf),
fv->data.fv_str.value, fv->data.fv_str.value_len);
PrintStringsToBuffer(printable_buf, &offset, len + 1, fv->data.fv_str.value,
fv->data.fv_str.value_len);

jb_start_object(js_flowvars);
jb_set_string(js_flowvars, varname, (char *)printable_buf);
Expand All @@ -288,16 +281,13 @@ static void EveAddFlowVars(const Flow *f, JsonBuilder *js_root, JsonBuilder **js

uint8_t keybuf[fv->keylen + 1];
uint32_t offset = 0;
PrintStringsToBuffer(keybuf, &offset,
sizeof(keybuf),
fv->key, fv->keylen);
PrintStringsToBuffer(keybuf, &offset, fv->keylen + 1, fv->key, fv->keylen);

uint32_t len = fv->data.fv_str.value_len;
uint8_t printable_buf[len + 1];
offset = 0;
PrintStringsToBuffer(printable_buf, &offset,
sizeof(printable_buf),
fv->data.fv_str.value, fv->data.fv_str.value_len);
PrintStringsToBuffer(printable_buf, &offset, len + 1, fv->data.fv_str.value,
fv->data.fv_str.value_len);

jb_start_object(js_flowvars);
jb_set_string(js_flowvars, (const char *)keybuf, (char *)printable_buf);
Expand Down Expand Up @@ -429,9 +419,9 @@ void EveAddCommonOptions(const OutputJsonCommonSettings *cfg, const Packet *p, c
* \param js JSON object
* \param max_length If non-zero, restricts the number of packet data bytes handled.
*/
void EvePacket(const Packet *p, JsonBuilder *js, unsigned long max_length)
void EvePacket(const Packet *p, JsonBuilder *js, uint32_t max_length)
{
unsigned long max_len = max_length == 0 ? GET_PKT_LEN(p) : max_length;
uint32_t max_len = max_length == 0 ? GET_PKT_LEN(p) : max_length;
jb_set_base64(js, "packet", GET_PKT_DATA(p), max_len);

if (!jb_open_object(js, "packet_info")) {
Expand Down Expand Up @@ -931,7 +921,8 @@ int OutputJSONMemBufferCallback(const char *str, size_t size, void *data)
MemBufferExpand(memb, wrapper->expand_by);
}

MemBufferWriteRaw((*memb), (const uint8_t *)str, size);
DEBUG_VALIDATE_BUG_ON(size > UINT32_MAX);
MemBufferWriteRaw((*memb), (const uint8_t *)str, (uint32_t)size);
return 0;
}

Expand Down Expand Up @@ -985,11 +976,12 @@ int OutputJsonBuilderBuffer(JsonBuilder *js, OutputJsonThreadCtx *ctx)
}

size_t jslen = jb_len(js);
DEBUG_VALIDATE_BUG_ON(jb_len(js) > UINT32_MAX);
if (MEMBUFFER_OFFSET(*buffer) + jslen >= MEMBUFFER_SIZE(*buffer)) {
MemBufferExpand(buffer, jslen);
MemBufferExpand(buffer, (uint32_t)jslen);
}

MemBufferWriteRaw((*buffer), jb_ptr(js), jslen);
MemBufferWriteRaw((*buffer), jb_ptr(js), (uint32_t)jslen);
LogFileWrite(file_ctx, *buffer);

return 0;
Expand Down Expand Up @@ -1144,7 +1136,7 @@ OutputInitResult OutputJsonInitCtx(ConfNode *conf)
{
FatalError("Failed to allocate memory for eve-log.prefix setting.");
}
json_ctx->file_ctx->prefix_len = strlen(prefix);
json_ctx->file_ctx->prefix_len = (uint32_t)strlen(prefix);
}

/* Threaded file output */
Expand Down
4 changes: 2 additions & 2 deletions src/output-json.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void JsonAddrInfoInit(const Packet *p, enum OutputJsonLogDirection dir,
/* helper struct for OutputJSONMemBufferCallback */
typedef struct OutputJSONMemBufferWrapper_ {
MemBuffer **buffer; /**< buffer to use & expand as needed */
size_t expand_by; /**< expand by this size */
uint32_t expand_by; /**< expand by this size */
} OutputJSONMemBufferWrapper;

typedef struct OutputJsonCommonSettings_ {
Expand Down Expand Up @@ -97,7 +97,7 @@ json_t *SCJsonString(const char *val);
void CreateEveFlowId(JsonBuilder *js, const Flow *f);
void EveFileInfo(JsonBuilder *js, const File *file, const uint64_t tx_id, const uint16_t flags);
void EveTcpFlags(uint8_t flags, JsonBuilder *js);
void EvePacket(const Packet *p, JsonBuilder *js, unsigned long max_length);
void EvePacket(const Packet *p, JsonBuilder *js, uint32_t max_length);
JsonBuilder *CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir,
const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx);
JsonBuilder *CreateEveHeaderWithTxId(const Packet *p, enum OutputJsonLogDirection dir,
Expand Down
3 changes: 2 additions & 1 deletion src/output-streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ static int TcpDataLogger (Flow *f, TcpSession *ssn, TcpStream *stream,
progress, &progress, eof);

if (progress > STREAM_LOG_PROGRESS(stream)) {
uint32_t slide = progress - STREAM_LOG_PROGRESS(stream);
DEBUG_VALIDATE_BUG_ON(progress - STREAM_LOG_PROGRESS(stream) > UINT32_MAX);
uint32_t slide = (uint32_t)(progress - STREAM_LOG_PROGRESS(stream));
stream->log_progress_rel += slide;
}

Expand Down
3 changes: 2 additions & 1 deletion src/stream-tcp-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,8 @@ void StreamTcpPruneSession(Flow *f, uint8_t flags)
const uint64_t left_edge = GetLeftEdge(f, ssn, stream);
SCLogDebug("buffer left_edge %" PRIu64, left_edge);
if (left_edge && left_edge > STREAM_BASE_OFFSET(stream)) {
uint32_t slide = left_edge - STREAM_BASE_OFFSET(stream);
DEBUG_VALIDATE_BUG_ON(left_edge - STREAM_BASE_OFFSET(stream) > UINT32_MAX);
uint32_t slide = (uint32_t)(left_edge - STREAM_BASE_OFFSET(stream));
SCLogDebug("buffer sliding %u to offset %"PRIu64, slide, left_edge);

if (!(ssn->flags & STREAMTCP_FLAG_APP_LAYER_DISABLED)) {
Expand Down
Loading