From 0d4efe0c0f184b43eddfe0866a18a8e565161cac 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 | 33 +++++++++++++++++++-------- src/app-layer-htp-range.h | 2 +- src/app-layer-htp.c | 12 +++++----- src/app-layer-http2.c | 10 ++++---- src/app-layer-smtp.c | 26 +++++++++++---------- src/app-layer-ssl.c | 44 ++++++++++++++++++------------------ src/app-layer-tftp.c | 2 +- 12 files changed, 90 insertions(+), 68 deletions(-) diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c index 68fca345f714..5748587f74bb 100644 --- a/src/app-layer-detect-proto.c +++ b/src/app-layer-detect-proto.c @@ -691,7 +691,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 5a5c63f5abf3..432bd020d230 100644 --- a/src/app-layer-frames.c +++ b/src/app-layer-frames.c @@ -372,7 +372,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); + DEBUG_VALIDATE_BUG_ON(o > le); + DEBUG_VALIDATE_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 @@ -383,7 +385,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; } @@ -796,7 +797,9 @@ static void FramePrune(Frames *frames, const TcpStream *stream, const bool eof) } } frames->cnt = x; - frames->left_edge_rel = le - STREAM_BASE_OFFSET(stream); + DEBUG_VALIDATE_BUG_ON(le < STREAM_BASE_OFFSET(stream)); + DEBUG_VALIDATE_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", @@ -804,7 +807,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 36a1018b466a..55a947b9f27a 100644 --- a/src/app-layer-ftp.c +++ b/src/app-layer-ftp.c @@ -378,7 +378,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 9bcff0668f1a..48f3a1a2ee5b 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); } @@ -182,13 +182,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 f0d75a9750c0..394966ac94e0 100644 --- a/src/app-layer-htp-range.c +++ b/src/app-layer-htp-range.c @@ -130,7 +130,7 @@ static void ContainerUrlRangeFree(void *s) static inline bool ContainerValueRangeTimeout(HttpRangeContainerFile *cu, const SCTime_t ts) { // we only timeout if we have no flow referencing us - if ((uint32_t)SCTIME_SECS(ts) > cu->expire || cu->error) { + if (SCTIME_CMP_GT(ts, cu->expire) || cu->error) { if (SC_ATOMIC_GET(cu->hdata->use_cnt) == 0) { DEBUG_VALIDATE_BUG_ON(cu->files == NULL); return true; @@ -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, SCTime_t expire) { cu->expire = expire; } @@ -246,7 +246,7 @@ static void *HttpRangeContainerUrlGet(const uint8_t *key, uint32_t keylen, const struct THashDataGetResult res = THashGetFromHash(ContainerUrlRangeList.ht, &lookup); if (res.data) { // nothing more to do if (res.is_new) - ContainerUrlRangeUpdate(res.data->data, SCTIME_SECS(ts) + ContainerUrlRangeList.timeout); + ContainerUrlRangeUpdate(res.data->data, SCTIME_ADD_SECS(ts, ContainerUrlRangeList.timeout)); HttpRangeContainerFile *c = res.data->data; c->hdata = res.data; SCLogDebug("c %p", c); @@ -412,9 +412,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; @@ -545,14 +545,21 @@ File *HttpRangeClose(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock // a new range just begins where we ended, append it if (range->gap > 0) { // if the range had a gap, begin by it - if (FileAppendData(c->container->files, sbcfg, NULL, range->gap) != 0) { + uint32_t gap = range->gap <= UINT32_MAX ? (uint32_t)range->gap : UINT32_MAX; + if (FileAppendData(c->container->files, sbcfg, NULL, gap) != 0) { c->container->lastsize = f->size; HttpRangeFileClose(sbcfg, c->container, flags | FILE_TRUNCATED); c->container->error = true; 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; @@ -564,7 +571,8 @@ File *HttpRangeClose(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock if (overlap < range->offset) { if (range->gap > 0) { // if the range had a gap, begin by it - if (FileAppendData(c->container->files, sbcfg, NULL, range->gap) != 0) { + uint32_t gap = range->gap <= UINT32_MAX ? (uint32_t)range->gap : UINT32_MAX; + if (FileAppendData(c->container->files, sbcfg, NULL, gap) != 0) { c->container->lastsize = f->size; HttpRangeFileClose(sbcfg, c->container, flags | FILE_TRUNCATED); c->container->error = true; @@ -573,8 +581,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 9ca28905501f..fb0dc5b76875 100644 --- a/src/app-layer-htp-range.h +++ b/src/app-layer-htp-range.h @@ -63,7 +63,7 @@ typedef struct HttpRangeContainerFile { /** key length */ uint32_t len; /** expire time in epoch */ - uint32_t expire; + SCTime_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 50b990157237..fd979ef7ddc9 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -548,12 +548,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); @@ -952,7 +952,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) { @@ -971,7 +971,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); if (bstr_cmp_c(h->value, "h2c") == 0) { if (AppLayerProtoDetectGetProtoName(ALPROTO_HTTP2) == NULL) { // if HTTP2 is disabled, keep the HTP_STREAM_TUNNEL mode @@ -1132,7 +1132,7 @@ static int HtpRequestBodySetupMultipart(htp_tx_t *tx, HtpTxUserData *htud) htp_header_t *h = (htp_header_t *)htp_table_get_c(tx->request_headers, "Content-Type"); if (h != NULL && bstr_len(h->value) > 0) { - htud->mime_state = SCMimeStateInit(bstr_ptr(h->value), bstr_len(h->value)); + htud->mime_state = SCMimeStateInit(bstr_ptr(h->value), (uint32_t)bstr_len(h->value)); if (htud->mime_state) { htud->tsflags |= HTP_BOUNDARY_SET; SCReturnInt(1); @@ -2460,7 +2460,7 @@ static void HTPConfigParseParameters(HTPCfgRec *cfg_prec, ConfNode *s, } /* set default soft-limit with our new hard limit */ SCLogConfig("Setting HTTP max-tx limit to %" PRIu32 " bytes", limit); - htp_config_set_max_tx(cfg_prec->cfg, (size_t)limit); + htp_config_set_max_tx(cfg_prec->cfg, limit); #endif } else if (strcasecmp("randomize-inspection-sizes", p->name) == 0) { if (!g_disable_randomness) { 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 26f469d93354..d1c2ae5a83f9 100644 --- a/src/app-layer-smtp.c +++ b/src/app-layer-smtp.c @@ -552,7 +552,7 @@ static AppLayerResult SMTPGetLine(Flow *f, StreamSlice *slice, SMTPState *state, * 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); @@ -759,8 +759,9 @@ static int SMTPProcessCommandDATA( // not an attachment break; } - depth = smtp_config.content_inspect_min_size + - (state->toserver_data_count - state->toserver_last_data_stamp); + depth = (uint32_t)(smtp_config.content_inspect_min_size + + (state->toserver_data_count - + state->toserver_last_data_stamp)); SCLogDebug("StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32, depth); StreamTcpReassemblySetMinInspectDepth(f->protoctx, STREAM_TOSERVER, depth); @@ -780,8 +781,9 @@ static int SMTPProcessCommandDATA( // rust already run FileAppendData if (tx->files_ts.tail && tx->files_ts.tail->content_inspected == 0 && tx->files_ts.tail->size >= smtp_config.content_inspect_min_size) { - depth = smtp_config.content_inspect_min_size + - (state->toserver_data_count - state->toserver_last_data_stamp); + depth = (uint32_t)(smtp_config.content_inspect_min_size + + (state->toserver_data_count - + state->toserver_last_data_stamp)); AppLayerParserTriggerRawStreamReassembly(f, STREAM_TOSERVER); SCLogDebug( "StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth); @@ -792,8 +794,9 @@ static int SMTPProcessCommandDATA( /* expand the limit as long as we get file data, as the file data is bigger * on the wire due to base64 */ } else { - depth = smtp_config.content_inspect_min_size + - (state->toserver_data_count - state->toserver_last_data_stamp); + depth = (uint32_t)(smtp_config.content_inspect_min_size + + (state->toserver_data_count - + state->toserver_last_data_stamp)); SCLogDebug("StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %" PRIu32, depth); StreamTcpReassemblySetMinInspectDepth(f->protoctx, STREAM_TOSERVER, depth); @@ -807,7 +810,8 @@ static int SMTPProcessCommandDATA( } else { SCLogDebug("File already closed"); } - depth = state->toserver_data_count - state->toserver_last_data_stamp; + depth = (uint32_t)(state->toserver_data_count - + state->toserver_last_data_stamp); AppLayerParserTriggerRawStreamReassembly(f, STREAM_TOSERVER); SCLogDebug("StreamTcpReassemblySetMinInspectDepth STREAM_TOSERVER %u", depth); StreamTcpReassemblySetMinInspectDepth(f->protoctx, STREAM_TOSERVER, depth); @@ -972,8 +976,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) { @@ -981,8 +984,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 6802fb18d743..da98a1ee0953 100644 --- a/src/app-layer-ssl.c +++ b/src/app-layer-ssl.c @@ -229,12 +229,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, @@ -587,7 +587,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) @@ -747,7 +747,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, @@ -774,7 +774,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, @@ -819,7 +819,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"); @@ -908,7 +908,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"); @@ -939,7 +939,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"); @@ -1001,7 +1001,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; @@ -1020,7 +1020,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"); @@ -1090,7 +1090,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"); @@ -1147,7 +1147,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"); @@ -1201,7 +1201,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"); @@ -1249,7 +1249,7 @@ static inline int TLSDecodeHSHelloExtensionSigAlgorithms( input += sigalgo_len; } - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("Signature algorithm list invalid length"); @@ -1319,7 +1319,7 @@ static inline int TLSDecodeHSHelloExtensionALPN( input += protolen; } - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("ALPN list invalid length"); @@ -1534,7 +1534,7 @@ static inline int TLSDecodeHSHelloExtensions(SSLState *ssl_state, } } - return (input - initial_input); + return (int)(input - initial_input); invalid_length: SCLogDebug("TLS handshake invalid length"); @@ -1907,7 +1907,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 */ @@ -1925,7 +1925,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); } /** @@ -2130,7 +2130,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, @@ -2214,7 +2214,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, @@ -2761,7 +2761,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; @@ -2786,7 +2786,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 0c08c6d58979..73fa44eda152 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); }