!8427 协议字段解析长度修正

Merge pull request !8427 from erestu/master
This commit is contained in:
openharmony_ci 2024-11-22 10:13:24 +00:00 committed by Gitee
commit 586328143e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -598,6 +598,85 @@ static uint8_t IsSettingFrameMtuAndTypeValid(const SettingFrame *netSettingFrame
return NSTACKX_TRUE;
}
static void DecodeSettingFrameDfxPayload(uint16_t payloadLength, SettingFrame *netSettingFrame,
SettingFrame *hostSettingFrame)
{
if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) +
sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability) +
sizeof(hostSettingFrame->capability) + sizeof(hostSettingFrame->dataFrameSize) +
sizeof(hostSettingFrame->capsCheck))) {
if (strnlen(netSettingFrame->productVersion, VERSION_STR_LEN) == VERSION_STR_LEN) {
(void)memset_s(hostSettingFrame->productVersion, VERSION_STR_LEN, 0, VERSION_STR_LEN);
DFILE_LOGD(TAG, "DFX, remote productVersion is wrong");
} else {
DFILE_LOGD(TAG, "DFX, remote productVersion: %s", netSettingFrame->productVersion);
if (strncpy_s(hostSettingFrame->productVersion, VERSION_STR_LEN,
netSettingFrame->productVersion, strlen(netSettingFrame->productVersion)) != 0) {
DFILE_LOGW(TAG, "DFX, Decode strncpy ProductVersion fail");
}
}
}
if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) +
sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability) +
sizeof(hostSettingFrame->capability) + sizeof(hostSettingFrame->dataFrameSize) +
sizeof(hostSettingFrame->capsCheck) + sizeof(hostSettingFrame->productVersion))) {
hostSettingFrame->isSupport160M = netSettingFrame->isSupport160M;
DFILE_LOGD(TAG, "DFX, DecodeSettingFrame, isSupport160M:%d", hostSettingFrame->isSupport160M);
}
}
static void DecodeSettingFrameInner(uint16_t payloadLength, SettingFrame *netSettingFrame,
SettingFrame *hostSettingFrame)
{
size_t hostFrameLength = 0;
hostSettingFrame->dFileVersion = ntohl(netSettingFrame->dFileVersion);
hostSettingFrame->abmCapability = ntohl(netSettingFrame->abmCapability);
hostFrameLength += sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) +
sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability);
if (payloadLength > hostFrameLength) {
hostSettingFrame->capability = ntohl(netSettingFrame->capability);
}
hostFrameLength += sizeof(hostSettingFrame->capability);
if (payloadLength > hostFrameLength) {
hostSettingFrame->dataFrameSize = ntohl(netSettingFrame->dataFrameSize);
}
hostFrameLength += sizeof(hostSettingFrame->dataFrameSize);
if (payloadLength > hostFrameLength) {
hostSettingFrame->capsCheck = ntohl(netSettingFrame->capsCheck);
}
/* DFX */
DecodeSettingFrameDfxPayload(payloadLength, netSettingFrame, hostSettingFrame);
hostFrameLength += sizeof(hostSettingFrame->capsCheck) + sizeof(hostSettingFrame->productVersion) +
sizeof(hostSettingFrame->isSupport160M);
if (payloadLength > hostFrameLength) {
hostSettingFrame->isSupportMtp = netSettingFrame->isSupportMtp;
hostSettingFrame->mtpPort = netSettingFrame->mtpPort;
}
hostFrameLength += sizeof(hostSettingFrame->isSupportMtp) + sizeof(hostSettingFrame->mtpPort);
if (payloadLength > hostFrameLength) {
hostSettingFrame->headerEnc = netSettingFrame->headerEnc;
}
hostFrameLength += sizeof(hostSettingFrame->headerEnc);
if (payloadLength > hostFrameLength) {
hostSettingFrame->mtpCapability = ntohl(netSettingFrame->mtpCapability);
}
hostFrameLength += sizeof(hostSettingFrame->mtpCapability);
if (payloadLength > hostFrameLength) {
hostSettingFrame->cipherCapability = ntohl(netSettingFrame->cipherCapability);
}
hostFrameLength += sizeof(hostSettingFrame->cipherCapability);
}
static int32_t DFileCheckSettingFrame(SettingFrame *netSettingFrame, SettingFrame *hostSettingFrame)
{
if (netSettingFrame->header.sessionId != 0 || netSettingFrame->header.transId != 0) {
@ -629,6 +708,7 @@ int32_t DecodeSettingFrame(SettingFrame *netSettingFrame, SettingFrame *hostSett
hostSettingFrame->header.sessionId = netSettingFrame->header.sessionId;
hostSettingFrame->mtu = ntohs(netSettingFrame->mtu);
hostSettingFrame->connType = ntohs(netSettingFrame->connType);
if (payloadLength == sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType)) {
/*
* In this condition, this netSettingFrame is from an old version and doesn't have the member dFileVersion.
@ -643,28 +723,7 @@ int32_t DecodeSettingFrame(SettingFrame *netSettingFrame, SettingFrame *hostSett
hostSettingFrame->dFileVersion = ntohl(netSettingFrame->dFileVersion);
hostSettingFrame->abmCapability = 0;
} else {
hostSettingFrame->dFileVersion = ntohl(netSettingFrame->dFileVersion);
hostSettingFrame->abmCapability = ntohl(netSettingFrame->abmCapability);
if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) +
sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability))) {
hostSettingFrame->capability = ntohl(netSettingFrame->capability);
}
if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) +
sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability) +
sizeof(hostSettingFrame->capability))) {
hostSettingFrame->dataFrameSize = ntohl(netSettingFrame->dataFrameSize);
}
if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) +
sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability) +
sizeof(hostSettingFrame->capability) + sizeof(hostSettingFrame->dataFrameSize))) {
hostSettingFrame->capsCheck = ntohl(netSettingFrame->capsCheck);
}
if (payloadLength > (sizeof(hostSettingFrame->mtu) + sizeof(hostSettingFrame->connType) +
sizeof(hostSettingFrame->dFileVersion) + sizeof(hostSettingFrame->abmCapability) +
sizeof(hostSettingFrame->capability) + sizeof(hostSettingFrame->dataFrameSize) +
sizeof(hostSettingFrame->capsCheck))) {
hostSettingFrame->cipherCapability = ntohl(netSettingFrame->cipherCapability);
}
DecodeSettingFrameInner(payloadLength, netSettingFrame, hostSettingFrame);
}
DFILE_LOGI(TAG, "local version is %u, remote version is %u capability 0x%x dataFrameSize %u capsCheck 0x%x "
"cipherCaps 0x%x",