Skip to content

Commit 3ccd50b

Browse files
# This is a combination of 2 commits.
# This is the 1st commit message: Check out of bounds for inactive type1 packet # The commit message #2 will be skipped: # fixup! Check out of bounds for inactive type1 packet
1 parent 135afeb commit 3ccd50b

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ add_executable(runUnitTestsEFP
5050
${CMAKE_CURRENT_SOURCE_DIR}/unitTests/UnitTest21.cpp
5151
${CMAKE_CURRENT_SOURCE_DIR}/unitTests/UnitTest22.cpp
5252
${CMAKE_CURRENT_SOURCE_DIR}/unitTests/UnitTest23.cpp
53+
${CMAKE_CURRENT_SOURCE_DIR}/unitTests/UnitTest24.cpp
5354
${CMAKE_CURRENT_SOURCE_DIR}/unitTests/UnitTestHelpers.cpp
5455
)
5556

ElasticFrameProtocol.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ ElasticFrameProtocolReceiver::unpackType1(const uint8_t *pSubPacket, size_t lPac
167167
pThisBucket->mActive = false;
168168
return ElasticFrameMessages::memoryAllocationError;
169169
}
170+
171+
if (pThisBucket->mOfFragmentNo < lType1Frame->hFragmentNo ||
172+
lType1Frame->hOfFragmentNo != pThisBucket->mOfFragmentNo) {
173+
EFP_LOGGER(true, LOGG_FATAL, "bufferOutOfBounds")
174+
mBucketMap.erase(pThisBucket->mDeliveryOrder);
175+
pThisBucket->mActive = false;
176+
return ElasticFrameMessages::bufferOutOfBounds;
177+
}
178+
170179
std::copy_n(pSubPacket + sizeof(ElasticFrameType1), lPacketSize - sizeof(ElasticFrameType1),
171180
pThisBucket->mBucketData->pFrameData + lInsertDataPointer);
172181
return ElasticFrameMessages::noError;

efp_c_api/main.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void send_data_callback(const uint8_t *data, size_t size, uint8_t stream_id, voi
4242
}
4343

4444
void receive_embedded_data_callback(uint8_t *data, size_t size, uint8_t data_type, uint64_t pts, void* ctx) {
45-
printf("Got embedded data: %zu bytes size and of type %d pts: %lu\n", size, data_type, pts);
45+
printf("Got embedded data: %zu bytes size and of type %d pts: %llu\n", size, data_type, pts);
4646
//In this example we know it's a string, print it.
4747
printf("Data: %s \n", data);
4848
printf("Context: %d \n\n", *(int*)ctx);
@@ -72,8 +72,8 @@ void receive_data_callback(uint8_t *data,
7272
printf("mFrameSize: %zu\n", size);
7373
printf("mDataContent: %d\n", data_content);
7474
printf("mBroken: %d\n", broken);
75-
printf("mPts: %lu\n", pts);
76-
printf("mDts: %lu\n", dts);
75+
printf("mPts: %llu\n", pts);
76+
printf("mDts: %llu\n", dts);
7777
printf("mCode: %d\n", code);
7878
printf("mStreamID: %d\n", stream_id);
7979
printf("mSource: %d\n", source);

unitTests/UnitTest24.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <memory>
4+
5+
#include "ElasticFrameProtocol.h"
6+
#include "ElasticInternal.h"
7+
#include "UnitTestHelpers.h"
8+
9+
// UnitTest24
10+
// Test unpack type1 packet
11+
TEST(UnitTest24, UnpackType1) {
12+
const size_t FRAME_SIZE = ((MTU - ElasticFrameProtocolSender::getType1Size()) * 5) + 12;
13+
std::unique_ptr<ElasticFrameProtocolReceiver> myEFPReceiver =
14+
std::make_unique<ElasticFrameProtocolReceiver>(50, 20);
15+
ElasticFrameType1 lType1Frame;
16+
17+
// test with nice type1 packet
18+
lType1Frame.hSuperFrameNo = 0;
19+
lType1Frame.hFrameType = Frametype::type1;
20+
ElasticFrameMessages result = myEFPReceiver->receiveFragmentFromPtr(reinterpret_cast<uint8_t*>(&lType1Frame), FRAME_SIZE, 0);
21+
EXPECT_EQ(result, ElasticFrameMessages::noError);
22+
23+
// test with corrupt type1 packet
24+
lType1Frame.hSuperFrameNo = 1;
25+
lType1Frame.hFragmentNo = 12345;
26+
result = myEFPReceiver->receiveFragmentFromPtr(reinterpret_cast<uint8_t*>(&lType1Frame), FRAME_SIZE, 0);
27+
EXPECT_EQ(result, ElasticFrameMessages::bufferOutOfBounds);
28+
}

0 commit comments

Comments
 (0)