FuzzTest bugfix

Signed-off-by: mayuecheng <mayuecheng@huawei.com>
This commit is contained in:
mayuecheng 2024-09-24 21:00:01 +08:00
parent 0cae2be76f
commit b2f1847bc6
5 changed files with 1 additions and 122 deletions

View File

@ -46,7 +46,7 @@ bool NrSsbInformation::Marshalling(Parcel &parcel) const
if (!parcel.WriteInt32(timeAdvance_)) {
return false;
}
for (int32_t i = 0; i < SCELL_SSB_LIST; ++i) {
for (int32_t i = 0; i < SCELL_SSB_LIST && i < sCellSsbList_.size(); ++i) {
if (!parcel.WriteInt32(sCellSsbList_[i].ssbId)) {
return false;
}

View File

@ -27,7 +27,6 @@ public:
std::shared_ptr<TelRilHandler> handler);
~TelRilSms() = default;
uint8_t *ConvertHexStringToBytes(const uint8_t *hexString, size_t length);
uint8_t ConvertHexCharToInt(uint8_t ch);
int32_t SendGsmSms(std::string &smsPdu, std::string &pdu, const AppExecFwk::InnerEvent::Pointer &response);

View File

@ -174,39 +174,6 @@ uint8_t TelRilSms::ConvertHexCharToInt(uint8_t ch)
}
}
uint8_t *TelRilSms::ConvertHexStringToBytes(const uint8_t *hexString, size_t length)
{
const int32_t HEX_NUM_PER_BYTE = 2;
const int32_t BIT_NUM_PER_HEX = 4;
if (length % HEX_NUM_PER_BYTE) {
return nullptr;
}
int32_t len = (int32_t)length / HEX_NUM_PER_BYTE;
if (len <= 0) {
TELEPHONY_LOGE("hexString is null");
return nullptr;
}
uint8_t *bytes = (uint8_t *)malloc(len * sizeof(uint8_t));
if (bytes == nullptr) {
TELEPHONY_LOGE("ConvertHexStringToBytes: cannot allocate memory for bytes string");
return nullptr;
}
uint8_t *hexStr = (uint8_t *)hexString;
size_t i = 0;
while (i < length) {
uint8_t hexCh1 = ConvertHexCharToInt(hexStr[i]);
uint8_t hexCh2 = ConvertHexCharToInt(hexStr[i + 1]);
if (hexCh1 == INVALID_HEX_CHAR || hexCh2 == INVALID_HEX_CHAR) {
free(bytes);
return nullptr;
}
bytes[i / HEX_NUM_PER_BYTE] = ((hexCh1 << BIT_NUM_PER_HEX) | hexCh2);
i += HEX_NUM_PER_BYTE;
}
return bytes;
}
int32_t TelRilSms::NewSmsNotify(const HDI::Ril::V1_1::SmsMessageInfo &iSmsMessageInfo)
{
std::shared_ptr<SmsMessageInfo> smsMessageInfo = std::make_shared<SmsMessageInfo>();

View File

@ -174,81 +174,6 @@ HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexCharToInt_004, Function | MediumT
EXPECT_EQ(expected, actual);
}
/**
* @tc.number TelRilSms_ConvertHexStringToBytes_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexStringToBytes_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t hexString[] = "12345";
uint8_t *result = telRilSms->ConvertHexStringToBytes(hexString, sizeof(hexString) - 1);
ASSERT_EQ(result, nullptr);
}
/**
* @tc.number TelRilSms_ConvertHexStringToBytes_002
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexStringToBytes_002, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t hexString[] = "";
uint8_t *result = telRilSms->ConvertHexStringToBytes(hexString, sizeof(hexString) - 1);
ASSERT_EQ(result, nullptr);
}
/**
* @tc.number TelRilSms_ConvertHexStringToBytes_003
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexStringToBytes_003, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t hexString[] = "123456";
uint8_t *result = telRilSms->ConvertHexStringToBytes(hexString, sizeof(hexString) - 1);
ASSERT_NE(result, nullptr);
}
/**
* @tc.number TelRilSms_ConvertHexStringToBytes_004
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexStringToBytes_004, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t hexString[] = "12345g";
uint8_t *result = telRilSms->ConvertHexStringToBytes(hexString, sizeof(hexString) - 1);
ASSERT_EQ(result, nullptr);
}
/**
* @tc.number TelRilSms_ConvertHexStringToBytes_005
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexStringToBytes_005, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t hexString[] = "123456";
uint8_t *result = telRilSms->ConvertHexStringToBytes(hexString, sizeof(hexString) - 1);
ASSERT_NE(result, nullptr);
}
/**
* @tc.number TelRilSms_GetSmscAddrResponse_001
* @tc.name test error branch

View File

@ -216,18 +216,6 @@ HWTEST_F(TelRilBranchTest, Telephony_tel_ril_Sms_001, Function | MediumTest | Le
ch = 67;
telRilSms->ConvertHexCharToInt(ch);
uint8_t hexString = 1;
size_t length = 1;
telRilSms->ConvertHexStringToBytes(&hexString, length);
hexString = 1;
length = 0;
telRilSms->ConvertHexStringToBytes(&hexString, length);
hexString = 1;
length = 2;
telRilSms->ConvertHexStringToBytes(&hexString, length);
HDI::Ril::V1_1::SmsMessageInfo iSmsMessageInfo;
telRilSms->NewSmsNotify(iSmsMessageInfo);
telRilSms->NewCdmaSmsNotify(iSmsMessageInfo);