From 17aa6d01255b73561918a6c52b9ca735c188b523 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 26 Jan 2024 14:32:59 -0500 Subject: [PATCH] IPv4: Make header fields go out of scope when no longer usable. There was a comment indicating where this happened, but then there was a use of one of them after this point. Fix that, and add { } around their use to prevent this from happening again. --- src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp b/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp index 6c10ff8c4b..44f0bf00bf 100644 --- a/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp +++ b/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp @@ -1707,6 +1707,8 @@ ipv4_receive_data(net_buffer* buffer) { TRACE("ipv4_receive_data(%p [%" B_PRIu32 " bytes])", buffer, buffer->size); + uint16 headerLength = 0; + { NetBufferHeaderReader bufferHeader(buffer); if (bufferHeader.Status() != B_OK) return bufferHeader.Status(); @@ -1718,7 +1720,7 @@ ipv4_receive_data(net_buffer* buffer) return B_BAD_TYPE; uint16 packetLength = header.TotalLength(); - uint16 headerLength = header.HeaderLength(); + headerLength = header.HeaderLength(); if (packetLength > buffer->size || headerLength < sizeof(ipv4_header)) return B_BAD_DATA; @@ -1810,13 +1812,13 @@ ipv4_receive_data(net_buffer* buffer) // Since the buffer might have been changed (reassembled fragment) // we must no longer access bufferHeader or header anymore after // this point + } bool rawDelivered = raw_receive_data(buffer); // Preserve the ipv4 header for ICMP processing gBufferModule->store_header(buffer); - - bufferHeader.Remove(headerLength); + gBufferModule->remove_header(buffer, headerLength); // the header is of variable size and may include IP options // (TODO: that we ignore for now)