From d88e53724081228e2e4712c77f3c32d085ba1301 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 29 Jun 2023 15:41:31 +0200 Subject: [PATCH] app-layer: fix -Wshorten-64-to-32 warnings Ticket: #6186 Warnings about downcast from 64 to 32 bits --- src/app-layer-detect-proto.c | 2 +- src/app-layer-dnp3-objects.c | 3 +- src/app-layer-frames.c | 10 ++++--- src/app-layer-ftp.c | 2 +- src/app-layer-htp-file.c | 12 +++++--- src/app-layer-htp-range.c | 23 +++++++++++---- src/app-layer-htp-range.h | 4 +-- src/app-layer-htp.c | 32 +++++++++++---------- src/app-layer-http2.c | 10 ++++--- src/app-layer-smtp.c | 55 +++++++++++++++++++++++++++--------- src/app-layer-ssl.c | 40 +++++++++++++------------- src/app-layer-tftp.c | 2 +- src/suricata-common.h | 2 +- src/util-streaming-buffer.c | 2 +- src/util-time.h | 4 +-- 15 files changed, 126 insertions(+), 77 deletions(-) diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c index 690950d34e72..ae1a9f9f1a09 100644 --- a/src/app-layer-detect-proto.c +++ b/src/app-layer-detect-proto.c @@ -686,7 +686,7 @@ static uint32_t AppLayerProtoDetectProbingParserGetMask(AppProto alproto) FatalError("Unknown protocol detected - %u", alproto); } - SCReturnUInt(1UL << (uint32_t)alproto); + SCReturnUInt(BIT_U32(alproto)); } static AppLayerProtoDetectProbingParserElement *AppLayerProtoDetectProbingParserElementAlloc(void) diff --git a/src/app-layer-dnp3-objects.c b/src/app-layer-dnp3-objects.c index 0bf9cd37bda2..42a46259f1a6 100644 --- a/src/app-layer-dnp3-objects.c +++ b/src/app-layer-dnp3-objects.c @@ -139,8 +139,7 @@ static int DNP3ReadUint24(const uint8_t **buf, uint32_t *len, uint32_t *out) *out = ((uint32_t)(*buf)[0] << 16) | ((uint32_t)(*buf)[1] << 8) | (uint32_t)(*buf)[2]; #elif __BYTE_ORDER == __LITTLE_ENDIAN - *out = ((uint64_t)(*buf)[0]) | ((uint64_t)(*buf)[1] << 8) | - ((uint64_t)(*buf)[2] << 16); + *out = ((uint32_t)(*buf)[0]) | ((uint32_t)(*buf)[1] << 8) | ((uint32_t)(*buf)[2] << 16); #endif *buf += 3; diff --git a/src/app-layer-frames.c b/src/app-layer-frames.c index 832752cf16e9..21c26054f251 100644 --- a/src/app-layer-frames.c +++ b/src/app-layer-frames.c @@ -342,7 +342,9 @@ static int FrameSlide(const char *ds, Frames *frames, const TcpStream *stream, c } frames->cnt = x; uint64_t o = STREAM_BASE_OFFSET(stream) + slide; - frames->left_edge_rel = le - (STREAM_BASE_OFFSET(stream) + slide); + BUG_ON(o > le); + BUG_ON(le - o > UINT32_MAX); + frames->left_edge_rel = (uint32_t)(le - o); #ifdef DEBUG SCLogDebug("end: left edge %" PRIu64 ", left_edge_rel %u, stream base %" PRIu64 @@ -353,7 +355,6 @@ static int FrameSlide(const char *ds, Frames *frames, const TcpStream *stream, c snprintf(pf, sizeof(pf), "%s:post_slide", ds); AppLayerFrameDumpForFrames(pf, frames); #endif - BUG_ON(o > le); BUG_ON(x != start - removed); return 0; } @@ -745,7 +746,9 @@ static void FramePrune(Frames *frames, const TcpStream *stream, const bool eof) } } frames->cnt = x; - frames->left_edge_rel = le - STREAM_BASE_OFFSET(stream); + BUG_ON(le < STREAM_BASE_OFFSET(stream)); + BUG_ON(le - STREAM_BASE_OFFSET(stream) > UINT32_MAX); + frames->left_edge_rel = (uint32_t)(le - STREAM_BASE_OFFSET(stream)); #ifdef DEBUG SCLogDebug("end: left edge %" PRIu64 ", left_edge_rel %u, stream base %" PRIu64 ", cnt %u, removed %u, start %u", @@ -753,7 +756,6 @@ static void FramePrune(Frames *frames, const TcpStream *stream, const bool eof) STREAM_BASE_OFFSET(stream), frames->cnt, removed, start); AppLayerFrameDumpForFrames("post_slide", frames); #endif - BUG_ON(le < STREAM_BASE_OFFSET(stream)); if (frames->cnt > 0) { // if we removed all this can fail BUG_ON(frames_le_start > le); } diff --git a/src/app-layer-ftp.c b/src/app-layer-ftp.c index 8925d6dd6a13..c4bd90012024 100644 --- a/src/app-layer-ftp.c +++ b/src/app-layer-ftp.c @@ -374,7 +374,7 @@ static AppLayerResult FTPGetLineForDirection( // lf_idx = 5010 // max_line_len = 4096 uint32_t o_consumed = input->consumed; - input->consumed = lf_idx - input->buf + 1; + input->consumed = (uint32_t)(lf_idx - input->buf + 1); line->len = input->consumed - o_consumed; input->len -= line->len; line->lf_found = true; diff --git a/src/app-layer-htp-file.c b/src/app-layer-htp-file.c index f96b37016061..74e18a7486cf 100644 --- a/src/app-layer-htp-file.c +++ b/src/app-layer-htp-file.c @@ -95,7 +95,7 @@ int HTPFileOpen(HtpState *s, HtpTxUserData *tx, const uint8_t *filename, uint16_ */ int HTPParseContentRange(bstr *rawvalue, HTTPContentRange *range) { - uint32_t len = bstr_len(rawvalue); + uint32_t len = (uint32_t)bstr_len(rawvalue); return rs_http_parse_content_range(range, bstr_ptr(rawvalue), len); } @@ -186,13 +186,17 @@ int HTPFileOpenWithRange(HtpState *s, HtpTxUserData *txud, const uint8_t *filena uint8_t *keyurl; uint32_t keylen; if (tx->request_hostname != NULL) { - keylen = bstr_len(tx->request_hostname) + filename_len; + uint32_t hlen = (uint32_t)bstr_len(tx->request_hostname); + if (bstr_len(tx->request_hostname) > UINT16_MAX) { + hlen = UINT16_MAX; + } + keylen = hlen + filename_len; keyurl = SCMalloc(keylen); if (keyurl == NULL) { SCReturnInt(-1); } - memcpy(keyurl, bstr_ptr(tx->request_hostname), bstr_len(tx->request_hostname)); - memcpy(keyurl + bstr_len(tx->request_hostname), filename, filename_len); + memcpy(keyurl, bstr_ptr(tx->request_hostname), hlen); + memcpy(keyurl + hlen, filename, filename_len); } else { // do not reassemble file without host info SCReturnInt(0); diff --git a/src/app-layer-htp-range.c b/src/app-layer-htp-range.c index 3cdde35ba288..68c44a897f45 100644 --- a/src/app-layer-htp-range.c +++ b/src/app-layer-htp-range.c @@ -139,7 +139,7 @@ static inline bool ContainerValueRangeTimeout(HttpRangeContainerFile *cu, const return false; } -static void ContainerUrlRangeUpdate(HttpRangeContainerFile *cu, uint32_t expire) +static void ContainerUrlRangeUpdate(HttpRangeContainerFile *cu, uint64_t expire) { cu->expire = expire; } @@ -410,9 +410,9 @@ int HttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBl if (c->files) { if (data == NULL) { // gap overlapping already known data - r = FileAppendData(c->files, sbcfg, NULL, len - c->toskip); + r = FileAppendData(c->files, sbcfg, NULL, (uint32_t)(len - c->toskip)); } else { - r = FileAppendData(c->files, sbcfg, data + c->toskip, len - c->toskip); + r = FileAppendData(c->files, sbcfg, data + c->toskip, (uint32_t)(len - c->toskip)); } } c->toskip = 0; @@ -550,7 +550,13 @@ File *HttpRangeClose(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock return f; } } - if (FileAppendData(c->container->files, sbcfg, range->buffer, range->offset) != 0) { + if (range->offset > UINT32_MAX) { + c->container->lastsize = f->size; + HttpRangeFileClose(sbcfg, c->container, flags | FILE_TRUNCATED); + c->container->error = true; + return f; + } else if (FileAppendData(c->container->files, sbcfg, range->buffer, + (uint32_t)range->offset) != 0) { c->container->lastsize = f->size; HttpRangeFileClose(sbcfg, c->container, flags | FILE_TRUNCATED); c->container->error = true; @@ -571,8 +577,13 @@ File *HttpRangeClose(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock } // And the range ends beyond where we ended // in this case of overlap, only add the extra data - if (FileAppendData(c->container->files, sbcfg, range->buffer + overlap, - range->offset - overlap) != 0) { + if (range->offset - overlap > UINT32_MAX) { + c->container->lastsize = f->size; + HttpRangeFileClose(sbcfg, c->container, flags | FILE_TRUNCATED); + c->container->error = true; + return f; + } else if (FileAppendData(c->container->files, sbcfg, range->buffer + overlap, + (uint32_t)(range->offset - overlap)) != 0) { c->container->lastsize = f->size; HttpRangeFileClose(sbcfg, c->container, flags | FILE_TRUNCATED); c->container->error = true; diff --git a/src/app-layer-htp-range.h b/src/app-layer-htp-range.h index 8a668aee6d2c..cf01c5b87629 100644 --- a/src/app-layer-htp-range.h +++ b/src/app-layer-htp-range.h @@ -40,7 +40,7 @@ typedef struct HttpRangeContainerBuffer { /** offset of bytes written in buffer (relative to the start of the range) */ uint64_t offset; /** number of gaped bytes */ - uint64_t gap; + uint32_t gap; } HttpRangeContainerBuffer; int HttpRangeContainerBufferCompare(HttpRangeContainerBuffer *a, HttpRangeContainerBuffer *b); @@ -63,7 +63,7 @@ typedef struct HttpRangeContainerFile { /** key length */ uint32_t len; /** expire time in epoch */ - uint32_t expire; + uint64_t expire; /** pointer to hashtable data, for locking and use count */ THashData *hdata; /** total expected size of the file in ranges */ diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 5d48611812c1..0af330446cf5 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -560,12 +560,12 @@ static uint32_t AppLayerHtpComputeChunkLength(uint64_t content_len_so_far, uint3 (content_len_so_far < (uint64_t)body_limit) && (content_len_so_far + (uint64_t)data_len) > body_limit) { - chunk_len = body_limit - content_len_so_far; + chunk_len = (uint32_t)(body_limit - content_len_so_far); } else if ((flags & HTP_STREAM_DEPTH_SET) && stream_depth > 0 && (content_len_so_far < (uint64_t)stream_depth) && (content_len_so_far + (uint64_t)data_len) > stream_depth) { - chunk_len = stream_depth - content_len_so_far; + chunk_len = (uint32_t)(stream_depth - content_len_so_far); } SCLogDebug("len %u", chunk_len); return (chunk_len == 0 ? data_len : chunk_len); @@ -963,7 +963,7 @@ static AppLayerResult HTPHandleResponseData(Flow *f, void *htp_state, AppLayerPa htp_time_t ts = { SCTIME_SECS(f->startts), SCTIME_USECS(f->startts) }; htp_tx_t *tx = NULL; - size_t consumed = 0; + uint32_t consumed = 0; if (input_len > 0) { const int r = htp_connp_res_data(hstate->connp, &ts, input, input_len); switch (r) { @@ -986,7 +986,7 @@ static AppLayerResult HTPHandleResponseData(Flow *f, void *htp_state, AppLayerPa if (tx->request_port_number != -1) { dp = (uint16_t)tx->request_port_number; } - consumed = htp_connp_res_data_consumed(hstate->connp); + consumed = (uint32_t)htp_connp_res_data_consumed(hstate->connp); hstate->slice = NULL; if (!AppLayerRequestProtocolChange(hstate->f, dp, ALPROTO_HTTP2)) { HTPSetEvent(hstate, NULL, STREAM_TOCLIENT, @@ -1273,7 +1273,7 @@ static void HtpRequestBodyMultipartParseHeader(HtpState *hstate, if (next_line == NULL) { line_len = header_len; } else { - line_len = next_line - header; + line_len = (uint32_t)(next_line - header); } uint8_t *sc = (uint8_t *)memchr(line, ':', line_len); if (sc == NULL) { @@ -1392,10 +1392,12 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud, /* end marker belonging to header_start */ const uint8_t *header_end = NULL; if (header_start != NULL) { - header_end = Bs2bmSearch(header_start, chunks_buffer_len - (header_start - chunks_buffer), + header_end = Bs2bmSearch(header_start, + (uint32_t)(chunks_buffer_len - (header_start - chunks_buffer)), (uint8_t *)"\r\n\r\n", 4); - form_end = Bs2bmSearch(header_start, chunks_buffer_len - (header_start - chunks_buffer), - boundary, expected_boundary_end_len); + form_end = Bs2bmSearch(header_start, + (uint32_t)(chunks_buffer_len - (header_start - chunks_buffer)), boundary, + expected_boundary_end_len); } SCLogDebug("header_start %p, header_end %p, form_end %p", header_start, @@ -1421,7 +1423,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud, } else if (header_start > filedata + 2) { SCLogDebug("some data from last file before the boundary"); /* some data from last file before the boundary */ - filedata_len = header_start - filedata - 2; + filedata_len = (uint32_t)(header_start - filedata - 2); } } /* body parsing done, we did not get our form end. Use all data @@ -1504,7 +1506,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud, uint8_t *filetype = NULL; uint16_t filetype_len = 0; - uint32_t header_len = header_end - header_start; + uint32_t header_len = (uint32_t)(header_end - header_start); SCLogDebug("header_len %u", header_len); uint8_t *header = (uint8_t *)header_start; @@ -1546,7 +1548,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud, goto end; } - filedata_len = form_end - (header_end + 4 + 2); + filedata_len = (uint32_t)(form_end - (header_end + 4 + 2)); SCLogDebug("filedata_len %"PRIuMAX, (uintmax_t)filedata_len); /* or is it? */ @@ -1587,7 +1589,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud, SCLogDebug("chunk doesn't contain form end"); filedata = header_end + 4; - filedata_len = chunks_buffer_len - (filedata - chunks_buffer); + filedata_len = (uint32_t)(chunks_buffer_len - (filedata - chunks_buffer)); SCLogDebug("filedata_len %u (chunks_buffer_len %u)", filedata_len, chunks_buffer_len); if (filedata_len > chunks_buffer_len) { @@ -1609,7 +1611,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud, if (header_next == NULL) { SCLogDebug("more file data to come"); - uint32_t offset = (header_end + 4) - chunks_buffer; + uint32_t offset = (uint32_t)((header_end + 4) - chunks_buffer); SCLogDebug("offset %u", offset); htud->request_body.body_parsed += offset; @@ -1642,7 +1644,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud, SCLogDebug("htud->request_body.body_parsed %"PRIu64, htud->request_body.body_parsed); } else if (header_next - filedata > 2) { - filedata_len = header_next - filedata - 2; + filedata_len = (uint32_t)(header_next - filedata - 2); SCLogDebug("filedata_len %u", filedata_len); result = HTPFileOpen(hstate, htud, filename, filename_len, filedata, @@ -1668,7 +1670,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud, header_start, header_end, form_end); /* Search next boundary entry after the start of body */ - uint32_t cursizeread = header_end - chunks_buffer; + uint32_t cursizeread = (uint32_t)(header_end - chunks_buffer); header_start = Bs2bmSearch(header_end + 4, chunks_buffer_len - (cursizeread + 4), boundary, expected_boundary_len); diff --git a/src/app-layer-http2.c b/src/app-layer-http2.c index dd0b3ec53f93..84f51ec5553b 100644 --- a/src/app-layer-http2.c +++ b/src/app-layer-http2.c @@ -82,16 +82,18 @@ void HTTP2MimicHttp1Request(void *alstate_orig, void *h2s) return; } // else - rs_http2_tx_set_method(h2s, bstr_ptr(h1tx->request_method), bstr_len(h1tx->request_method)); + rs_http2_tx_set_method( + h2s, bstr_ptr(h1tx->request_method), (uint32_t)bstr_len(h1tx->request_method)); if (h1tx->request_uri != NULL) { // A request line without spaces gets interpreted as a request_method // and has request_uri=NULL - rs_http2_tx_set_uri(h2s, bstr_ptr(h1tx->request_uri), bstr_len(h1tx->request_uri)); + rs_http2_tx_set_uri( + h2s, bstr_ptr(h1tx->request_uri), (uint32_t)bstr_len(h1tx->request_uri)); } size_t nbheaders = htp_table_size(h1tx->request_headers); for (size_t i = 0; i < nbheaders; i++) { htp_header_t *h = htp_table_get_index(h1tx->request_headers, i, NULL); - rs_http2_tx_add_header( - h2s, bstr_ptr(h->name), bstr_len(h->name), bstr_ptr(h->value), bstr_len(h->value)); + rs_http2_tx_add_header(h2s, bstr_ptr(h->name), (uint32_t)bstr_len(h->name), + bstr_ptr(h->value), (uint32_t)bstr_len(h->value)); } } diff --git a/src/app-layer-smtp.c b/src/app-layer-smtp.c index a4d94a94ded2..862ff3219c34 100644 --- a/src/app-layer-smtp.c +++ b/src/app-layer-smtp.c @@ -519,8 +519,15 @@ int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, flags |= FILE_STORE; } - uint32_t depth = smtp_config.content_inspect_min_size + - (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp); + uint32_t depth = (uint32_t)( + smtp_config.content_inspect_min_size + + (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp)); + if (smtp_config.content_inspect_min_size + + (smtp_state->toserver_data_count - + smtp_state->toserver_last_data_stamp) > + UINT32_MAX) { + depth = UINT32_MAX; + } SCLogDebug("StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %"PRIu32, depth); StreamTcpReassemblySetMinInspectDepth(flow->protoctx, STREAM_TOSERVER, depth); @@ -551,7 +558,12 @@ int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, } else { SCLogDebug("File already closed"); } - depth = smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp; + depth = (uint32_t)( + smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp); + if (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp > + UINT32_MAX) { + depth = UINT32_MAX; + } AppLayerParserTriggerRawStreamReassembly(flow, STREAM_TOSERVER); SCLogDebug("StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", @@ -572,7 +584,12 @@ int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, } else { SCLogDebug("File already closed"); } - uint32_t depth = smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp; + uint32_t depth = (uint32_t)( + smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp); + if (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp > + UINT32_MAX) { + depth = UINT32_MAX; + } AppLayerParserTriggerRawStreamReassembly(flow, STREAM_TOSERVER); SCLogDebug("StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth); @@ -593,8 +610,15 @@ int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, if (files->tail && files->tail->content_inspected == 0 && files->tail->size >= smtp_config.content_inspect_min_size) { - uint32_t depth = smtp_config.content_inspect_min_size + - (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp); + uint32_t depth = (uint32_t)( + smtp_config.content_inspect_min_size + + (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp)); + if (smtp_config.content_inspect_min_size + + (smtp_state->toserver_data_count - + smtp_state->toserver_last_data_stamp) > + UINT32_MAX) { + depth = UINT32_MAX; + } AppLayerParserTriggerRawStreamReassembly(flow, STREAM_TOSERVER); SCLogDebug("StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth); @@ -609,8 +633,15 @@ int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, /* expand the limit as long as we get file data, as the file data is bigger on the * wire due to base64 */ } else { - uint32_t depth = smtp_config.content_inspect_min_size + - (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp); + uint32_t depth = (uint32_t)( + smtp_config.content_inspect_min_size + + (smtp_state->toserver_data_count - smtp_state->toserver_last_data_stamp)); + if (smtp_config.content_inspect_min_size + + (smtp_state->toserver_data_count - + smtp_state->toserver_last_data_stamp) > + UINT32_MAX) { + depth = UINT32_MAX; + } SCLogDebug("StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %"PRIu32, depth); StreamTcpReassemblySetMinInspectDepth(flow->protoctx, @@ -663,7 +694,7 @@ static AppLayerResult SMTPGetLine( * lf_idx = 5010 * max_line_len = 4096 */ uint32_t o_consumed = input->consumed; - input->consumed = lf_idx - input->buf + 1; + input->consumed = (uint32_t)(lf_idx - input->buf + 1); line->len = input->consumed - o_consumed; line->lf_found = true; DEBUG_VALIDATE_BUG_ON(line->len < 0); @@ -1028,8 +1059,7 @@ static int SMTPParseCommandBDAT(SMTPState *state, const SMTPLine *line) /* decoder event */ return -1; } - char *endptr = NULL; - // copy in temporary null-terminated buffer to call strtoul + // copy in temporary null-terminated buffer to call StringParseUint32 char strbuf[24]; int len = 23; if (line->len - i < len) { @@ -1037,8 +1067,7 @@ static int SMTPParseCommandBDAT(SMTPState *state, const SMTPLine *line) } memcpy(strbuf, line->buf + i, len); strbuf[len] = '\0'; - state->bdat_chunk_len = strtoul((const char *)strbuf, (char **)&endptr, 10); - if ((uint8_t *)endptr == line->buf + i) { + if (StringParseUint32(&state->bdat_chunk_len, 10, 0, strbuf) < 0) { /* decoder event */ return -1; } diff --git a/src/app-layer-ssl.c b/src/app-layer-ssl.c index cb094f3801ab..cd0fb9729c05 100644 --- a/src/app-layer-ssl.c +++ b/src/app-layer-ssl.c @@ -225,12 +225,12 @@ struct SSLDecoderResult { #define SSL_DECODER_OK(c) \ (struct SSLDecoderResult) \ { \ - (c), 0 \ + (uint32_t)(c), 0 \ } #define SSL_DECODER_INCOMPLETE(c, n) \ (struct SSLDecoderResult) \ { \ - (c), (n) \ + (uint32_t)(c), (n) \ } static inline int SafeMemcpy(void *dst, size_t dst_offset, size_t dst_size, @@ -572,7 +572,7 @@ static int TlsDecodeHSCertificate(SSLState *ssl_state, SSLStateConnp *connp, next: input += cert_len; - return (input - initial_input); + return (int)(input - initial_input); error: if (err_code != 0) @@ -725,7 +725,7 @@ static inline int TLSDecodeHSHelloVersion(SSLState *ssl_state, input += SSLV3_CLIENT_HELLO_VERSION_LEN; - return (input - initial_input); + return (int)(input - initial_input); } static inline int TLSDecodeHSHelloRandom(SSLState *ssl_state, @@ -752,7 +752,7 @@ static inline int TLSDecodeHSHelloRandom(SSLState *ssl_state, /* Skip random */ input += SSLV3_CLIENT_HELLO_RANDOM_LEN; - return (input - initial_input); + return (int)(input - initial_input); } static inline int TLSDecodeHSHelloSessionID(SSLState *ssl_state, @@ -797,7 +797,7 @@ static inline int TLSDecodeHSHelloSessionID(SSLState *ssl_state, input += session_id_length; - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("TLS handshake invalid length"); @@ -872,7 +872,7 @@ static inline int TLSDecodeHSHelloCipherSuites(SSLState *ssl_state, input += cipher_suites_length; } - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("TLS handshake invalid length"); @@ -903,7 +903,7 @@ static inline int TLSDecodeHSHelloCompressionMethods(SSLState *ssl_state, input += compression_methods_length; } - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("TLS handshake invalid_length"); @@ -965,7 +965,7 @@ static inline int TLSDecodeHSHelloExtensionSni(SSLState *ssl_state, SSLSetEvent(ssl_state, TLS_DECODER_EVENT_MULTIPLE_SNI_EXTENSIONS); input += sni_len; - return (input - initial_input); + return (int)(input - initial_input); } const size_t sni_strlen = sni_len + 1; @@ -984,7 +984,7 @@ static inline int TLSDecodeHSHelloExtensionSni(SSLState *ssl_state, input += sni_len; - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("TLS handshake invalid length"); @@ -1050,7 +1050,7 @@ static inline int TLSDecodeHSHelloExtensionSupportedVersions(SSLState *ssl_state input += 2; } - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("TLS handshake invalid length"); @@ -1107,7 +1107,7 @@ static inline int TLSDecodeHSHelloExtensionEllipticCurves(SSLState *ssl_state, input += elliptic_curves_len; } - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("TLS handshake invalid length"); @@ -1161,7 +1161,7 @@ static inline int TLSDecodeHSHelloExtensionEllipticCurvePF(SSLState *ssl_state, input += ec_pf_len; } - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("TLS handshake invalid length"); @@ -1348,7 +1348,7 @@ static inline int TLSDecodeHSHelloExtensions(SSLState *ssl_state, } } - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("TLS handshake invalid length"); @@ -1712,7 +1712,7 @@ static int SSLv3ParseHandshakeProtocol(SSLState *ssl_state, const uint8_t *input ssl_state->curr_connp->hs_buffer_message_size); input += input_len; SSLParserHSReset(ssl_state->curr_connp); - return (input - initial_input); + return (int)(input - initial_input); } else { /* full record, parse it now */ @@ -1730,7 +1730,7 @@ static int SSLv3ParseHandshakeProtocol(SSLState *ssl_state, const uint8_t *input } SCLogDebug("input_len left %u", input_len); } - return (input - initial_input); + return (int)(input - initial_input); } /** @@ -1935,7 +1935,7 @@ static int SSLv3ParseRecord(uint8_t direction, SSLState *ssl_state, ssl_state->curr_connp->bytes_processed += (input - initial_input); - return (input - initial_input); + return (int)(input - initial_input); } static int SSLv2ParseRecord(uint8_t direction, SSLState *ssl_state, @@ -2019,7 +2019,7 @@ static int SSLv2ParseRecord(uint8_t direction, SSLState *ssl_state, ssl_state->curr_connp->bytes_processed += (input - initial_input); - return (input - initial_input); + return (int)(input - initial_input); } static struct SSLDecoderResult SSLv2Decode(uint8_t direction, SSLState *ssl_state, @@ -2566,7 +2566,7 @@ static AppLayerResult SSLDecode(Flow *f, uint8_t direction, void *alstate, input += r.retval; SCLogDebug("returning consumed %" PRIuMAX " needed %u", (uintmax_t)(input - init_input), r.needed); - SCReturnStruct(APP_LAYER_INCOMPLETE(input - init_input, r.needed)); + SCReturnStruct(APP_LAYER_INCOMPLETE((uint32_t)(input - init_input), r.needed)); } input_len -= r.retval; input += r.retval; @@ -2591,7 +2591,7 @@ static AppLayerResult SSLDecode(Flow *f, uint8_t direction, void *alstate, input += r.retval; SCLogDebug("returning consumed %" PRIuMAX " needed %u", (uintmax_t)(input - init_input), r.needed); - SCReturnStruct(APP_LAYER_INCOMPLETE(input - init_input, r.needed)); + SCReturnStruct(APP_LAYER_INCOMPLETE((uint32_t)(input - init_input), r.needed)); } input_len -= r.retval; input += r.retval; diff --git a/src/app-layer-tftp.c b/src/app-layer-tftp.c index 73dc52a59eac..3944221fc972 100644 --- a/src/app-layer-tftp.c +++ b/src/app-layer-tftp.c @@ -113,7 +113,7 @@ static AppLayerResult TFTPParseRequest(Flow *f, void *state, AppLayerParserState SCReturnStruct(APP_LAYER_OK); } - int res = rs_tftp_request(state, input, input_len); + int64_t res = rs_tftp_request(state, input, input_len); if (res < 0) { SCReturnStruct(APP_LAYER_ERROR); } diff --git a/src/suricata-common.h b/src/suricata-common.h index 297a6fc4521e..8635634d0a8c 100644 --- a/src/suricata-common.h +++ b/src/suricata-common.h @@ -397,7 +397,7 @@ typedef unsigned char u_char; #define BIT_U8(n) ((uint8_t)(1 << (n))) #define BIT_U16(n) ((uint16_t)(1 << (n))) -#define BIT_U32(n) (1UL << (n)) +#define BIT_U32(n) ((uint32_t)(1UL << (n))) #define BIT_U64(n) (1ULL << (n)) #define WARN_UNUSED __attribute__((warn_unused_result)) diff --git a/src/util-streaming-buffer.c b/src/util-streaming-buffer.c index 7608b5082109..b8f736015baf 100644 --- a/src/util-streaming-buffer.c +++ b/src/util-streaming-buffer.c @@ -708,7 +708,7 @@ static inline int WARN_UNUSED GrowRegionToSize(StreamingBuffer *sb, if (size > BIT_U32(30)) { // 1GiB if (!g2s_warn_once) { SCLogWarning("StreamingBuffer::GrowRegionToSize() tried to alloc %u bytes, exceeds " - "limit of %lu", + "limit of %" PRIu32, size, BIT_U32(30)); g2s_warn_once = true; } diff --git a/src/util-time.h b/src/util-time.h index 9bbd8798dd17..941a762d2121 100644 --- a/src/util-time.h +++ b/src/util-time.h @@ -53,8 +53,8 @@ typedef struct { { \ .secs = 0, .usecs = 0 \ } -#define SCTIME_USECS(t) ((uint64_t)(t).usecs) -#define SCTIME_SECS(t) ((uint64_t)(t).secs) +#define SCTIME_USECS(t) ((t).usecs) +#define SCTIME_SECS(t) ((t).secs) #define SCTIME_MSECS(t) (SCTIME_SECS(t) * 1000 + SCTIME_USECS(t) / 1000) #define SCTIME_ADD_SECS(ts, s) SCTIME_FROM_SECS((ts).secs + (s)) #define SCTIME_ADD_USECS(ts, us) SCTIME_FROM_USECS((ts).usecs + (us))