Skip to content

Commit

Permalink
stream: fix -Wshorten-64-to-32 warnings
Browse files Browse the repository at this point in the history
Ticket: #6186
  • Loading branch information
catenacyber committed Oct 8, 2024
1 parent 035a367 commit fd44983
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
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
16 changes: 9 additions & 7 deletions src/stream-tcp-reassemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,9 +1092,9 @@ static bool GetAppBuffer(const TcpStream *stream, const uint8_t **data, uint32_t
"got data at %"PRIu64". GAP of size %"PRIu64,
offset, blk->offset, blk->offset - offset);
*data = NULL;
*data_len = blk->offset - offset;
*data_len = (uint32_t)(blk->offset - offset);

/* block starts before offset, but ends after */
/* block starts before offset, but ends after */
} else if (offset > blk->offset && offset <= (blk->offset + blk->len)) {
SCLogDebug("get data from offset %"PRIu64". SBB %"PRIu64"/%u",
offset, blk->offset, blk->len);
Expand Down Expand Up @@ -1184,7 +1184,7 @@ static inline uint32_t AdjustToAcked(const Packet *p,
/* see if the buffer contains unack'd data as well */
if (app_progress <= last_ack_abs && app_progress + data_len > last_ack_abs) {
uint32_t check = data_len;
adjusted = last_ack_abs - app_progress;
adjusted = (uint32_t)(last_ack_abs - app_progress);
BUG_ON(adjusted > check);
SCLogDebug("data len adjusted to %u to make sure only ACK'd "
"data is considered", adjusted);
Expand Down Expand Up @@ -1414,7 +1414,7 @@ static int GetRawBuffer(const TcpStream *stream, const uint8_t **data, uint32_t
uint64_t delta = offset - (*iter)->offset;
if (delta < mydata_len) {
*data = mydata + delta;
*data_len = mydata_len - delta;
*data_len = (uint32_t)(mydata_len - delta);
*data_offset = offset;
} else {
SCLogDebug("no data (yet)");
Expand Down Expand Up @@ -1498,7 +1498,8 @@ void StreamReassembleRawUpdateProgress(TcpSession *ssn, Packet *p, const uint64_
}

if (progress > STREAM_RAW_PROGRESS(stream)) {
uint32_t slide = progress - STREAM_RAW_PROGRESS(stream);
DEBUG_VALIDATE_BUG_ON(progress - STREAM_RAW_PROGRESS(stream) > UINT32_MAX);
uint32_t slide = (uint32_t)(progress - STREAM_RAW_PROGRESS(stream));
stream->raw_progress_rel += slide;
stream->flags &= ~STREAMTCP_STREAM_FLAG_TRIGGER_RAW;

Expand All @@ -1510,7 +1511,8 @@ void StreamReassembleRawUpdateProgress(TcpSession *ssn, Packet *p, const uint64_
target = GetAbsLastAck(stream);
}
if (target > STREAM_RAW_PROGRESS(stream)) {
uint32_t slide = target - STREAM_RAW_PROGRESS(stream);
DEBUG_VALIDATE_BUG_ON(target - STREAM_RAW_PROGRESS(stream) > UINT32_MAX);
uint32_t slide = (uint32_t)(target - STREAM_RAW_PROGRESS(stream));
stream->raw_progress_rel += slide;
}
stream->flags &= ~STREAMTCP_STREAM_FLAG_TRIGGER_RAW;
Expand Down Expand Up @@ -1781,7 +1783,7 @@ static int StreamReassembleRawDo(const TcpSession *ssn, const TcpStream *stream,
/* see if the buffer contains unack'd data as well */
if (progress + mydata_len > re) {
uint32_t check = mydata_len;
mydata_len = re - progress;
mydata_len = (uint32_t)(re - progress);
BUG_ON(check < mydata_len);
SCLogDebug("data len adjusted to %u to make sure only ACK'd "
"data is considered", mydata_len);
Expand Down
28 changes: 14 additions & 14 deletions src/stream-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ static int StreamTcpPacketStateNone(

ssn->flags |= STREAMTCP_FLAG_TIMESTAMP;

ssn->client.last_pkt_ts = SCTIME_SECS(p->ts);
ssn->client.last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);
if (ssn->server.last_ts == 0)
ssn->server.flags |= STREAMTCP_STREAM_FLAG_ZERO_TIMESTAMP;
if (ssn->client.last_ts == 0)
Expand Down Expand Up @@ -1294,7 +1294,7 @@ static int StreamTcpPacketStateNone(

ssn->flags |= STREAMTCP_FLAG_TIMESTAMP;

ssn->server.last_pkt_ts = SCTIME_SECS(p->ts);
ssn->server.last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);
if (ssn->server.last_ts == 0)
ssn->server.flags |= STREAMTCP_STREAM_FLAG_ZERO_TIMESTAMP;
if (ssn->client.last_ts == 0)
Expand Down Expand Up @@ -1347,7 +1347,7 @@ static int StreamTcpPacketStateNone(
if (ssn->client.last_ts == 0)
ssn->client.flags |= STREAMTCP_STREAM_FLAG_ZERO_TIMESTAMP;

ssn->client.last_pkt_ts = SCTIME_SECS(p->ts);
ssn->client.last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);
ssn->client.flags |= STREAMTCP_STREAM_FLAG_TIMESTAMP;
}

Expand Down Expand Up @@ -1455,7 +1455,7 @@ static int StreamTcpPacketStateNone(

ssn->flags |= STREAMTCP_FLAG_TIMESTAMP;

ssn->client.last_pkt_ts = SCTIME_SECS(p->ts);
ssn->client.last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);
if (ssn->server.last_ts == 0)
ssn->server.flags |= STREAMTCP_STREAM_FLAG_ZERO_TIMESTAMP;
if (ssn->client.last_ts == 0)
Expand Down Expand Up @@ -1490,7 +1490,7 @@ static inline void StreamTcp3whsSynAckToStateQueue(Packet *p, TcpStateQueue *q)
q->win = TCP_GET_RAW_WINDOW(tcph);
q->seq = TCP_GET_RAW_SEQ(tcph);
q->ack = TCP_GET_RAW_ACK(tcph);
q->pkt_ts = SCTIME_SECS(p->ts);
q->pkt_ts = (uint32_t)SCTIME_SECS(p->ts);

if (TCP_GET_SACKOK(p))
q->flags |= STREAMTCP_QUEUE_FLAG_SACK;
Expand Down Expand Up @@ -1753,7 +1753,7 @@ static void TcpStateQueueInitFromPktSyn(const Packet *p, TcpStateQueue *q)
const TCPHdr *tcph = PacketGetTCP(p);

q->win = TCP_GET_RAW_WINDOW(tcph);
q->pkt_ts = SCTIME_SECS(p->ts);
q->pkt_ts = (uint32_t)SCTIME_SECS(p->ts);

if (TCP_GET_SACKOK(p)) {
q->flags |= STREAMTCP_QUEUE_FLAG_SACK;
Expand Down Expand Up @@ -1786,7 +1786,7 @@ static void TcpStateQueueInitFromPktSynAck(const Packet *p, TcpStateQueue *q)

const TCPHdr *tcph = PacketGetTCP(p);
q->win = TCP_GET_RAW_WINDOW(tcph);
q->pkt_ts = SCTIME_SECS(p->ts);
q->pkt_ts = (uint32_t)SCTIME_SECS(p->ts);

if (TCP_GET_SACKOK(p)) {
q->flags |= STREAMTCP_QUEUE_FLAG_SACK;
Expand Down Expand Up @@ -2025,7 +2025,7 @@ static int StreamTcpPacketStateSynSent(
"ssn->server.last_ts %" PRIu32 "",
ssn, ssn->client.last_ts, ssn->server.last_ts);
ssn->flags |= STREAMTCP_FLAG_TIMESTAMP;
ssn->client.last_pkt_ts = SCTIME_SECS(p->ts);
ssn->client.last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);
if (ssn->client.last_ts == 0)
ssn->client.flags |= STREAMTCP_STREAM_FLAG_ZERO_TIMESTAMP;
} else {
Expand Down Expand Up @@ -2131,7 +2131,7 @@ static int StreamTcpPacketStateSynSent(

if (ssn->server.last_ts == 0)
ssn->server.flags |= STREAMTCP_STREAM_FLAG_ZERO_TIMESTAMP;
ssn->server.last_pkt_ts = SCTIME_SECS(p->ts);
ssn->server.last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);
ssn->server.flags |= STREAMTCP_STREAM_FLAG_TIMESTAMP;
}

Expand Down Expand Up @@ -2233,7 +2233,7 @@ static int StreamTcpPacketStateSynSent(
{
ssn->flags |= STREAMTCP_FLAG_TIMESTAMP;
ssn->client.flags &= ~STREAMTCP_STREAM_FLAG_TIMESTAMP;
ssn->client.last_pkt_ts = SCTIME_SECS(p->ts);
ssn->client.last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);
} else {
ssn->client.last_ts = 0;
ssn->client.flags &= ~STREAMTCP_STREAM_FLAG_ZERO_TIMESTAMP;
Expand Down Expand Up @@ -6350,7 +6350,7 @@ static int StreamTcpValidateTimestamp (TcpSession *ssn, Packet *p)
if (last_pkt_ts == 0 &&
(ssn->flags & STREAMTCP_FLAG_MIDSTREAM))
{
last_pkt_ts = SCTIME_SECS(p->ts);
last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);
}

if (result < 0) {
Expand Down Expand Up @@ -6494,7 +6494,7 @@ static int StreamTcpHandleTimestamp (TcpSession *ssn, Packet *p)
if (sender_stream->last_pkt_ts == 0 &&
(ssn->flags & STREAMTCP_FLAG_MIDSTREAM))
{
sender_stream->last_pkt_ts = SCTIME_SECS(p->ts);
sender_stream->last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);
}

if (result < 0) {
Expand All @@ -6519,7 +6519,7 @@ static int StreamTcpHandleTimestamp (TcpSession *ssn, Packet *p)
if (SEQ_EQ(sender_stream->next_seq, seq))
sender_stream->last_ts = ts;

sender_stream->last_pkt_ts = SCTIME_SECS(p->ts);
sender_stream->last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);

} else if (ret == 0) {
/* if the timestamp of packet is not valid then, check if the
Expand All @@ -6529,7 +6529,7 @@ static int StreamTcpHandleTimestamp (TcpSession *ssn, Packet *p)
(((uint32_t)SCTIME_SECS(p->ts) >
(sender_stream->last_pkt_ts + PAWS_24DAYS)))) {
sender_stream->last_ts = ts;
sender_stream->last_pkt_ts = SCTIME_SECS(p->ts);
sender_stream->last_pkt_ts = (uint32_t)SCTIME_SECS(p->ts);

SCLogDebug("timestamp considered valid anyway");
} else {
Expand Down

0 comments on commit fd44983

Please sign in to comment.