fix overflow

Signed-off-by: Mark <liudongmiao@huawei.com>
This commit is contained in:
Mark 2022-11-08 11:03:36 +00:00
parent 2e00bff340
commit 6645de5361
4 changed files with 33 additions and 12 deletions

View File

@ -73,11 +73,13 @@
#define SHORT_DEVICE_ID_HASH_LENGTH 8
#define BT_MAX_STR_LEN 18
#define BT_MAC_BYTES_LEN 6
#define DEVICE_TYPE_LEN 1
#define DEVICE_TYPE_LEN 2
#define DEVICE_TYPE_MASK 0xFF
#define ONE_BYTE_LENGTH 8
#define RANGE_POWER_TYPE_LEN 1
#define TL_LEN 1
#define MAX_BROADCAST_DATA_LEN 31
#define SCAN_RSP_HEADER_LEN 4
#endif
#endif

View File

@ -54,7 +54,7 @@ void UnsetCapBitMapPos(uint32_t capBitMapNum, uint32_t *capBitMap, uint32_t pos)
int32_t DiscBleGetDeviceUdid(char *udid, uint32_t len);
int32_t DiscBleGetDeviceName(char *deviceName);
uint8_t DiscBleGetDeviceType(void);
uint16_t DiscBleGetDeviceType(void);
int32_t DiscBleGetDeviceIdHash(unsigned char *hashStr);
int32_t DiscBleGetShortUserIdHash(unsigned char *hashStr, uint32_t len);
@ -66,4 +66,4 @@ int32_t GetDeviceInfoFromDisAdvData(DeviceWrapper *info, const unsigned char *da
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif
#endif

View File

@ -786,10 +786,17 @@ static int32_t GetBroadcastData(DeviceInfo *info, int32_t advId, BoardcastData *
if (DiscBleGetDeviceIdHash((unsigned char *)deviceIdHash) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "Get deviceId Hash failed");
}
uint8_t devType = info->devType;
(void)AssembleTLV(boardcastData, TLV_TYPE_DEVICE_ID_HASH, (const void *)deviceIdHash,
SHORT_DEVICE_ID_HASH_LENGTH);
(void)AssembleTLV(boardcastData, TLV_TYPE_DEVICE_TYPE, (const void *)&devType, DEVICE_TYPE_LEN);
uint16_t devType = info->devType;
uint8_t sendDevType[DEVICE_TYPE_LEN] = {0};
uint32_t devTypeLen = 1;
sendDevType[0] = devType & DEVICE_TYPE_MASK;
if (devType >= (1 << ONE_BYTE_LENGTH)) {
sendDevType[1] = (devType >> ONE_BYTE_LENGTH) & DEVICE_TYPE_MASK;
devTypeLen++;
}
(void)AssembleTLV(boardcastData, TLV_TYPE_DEVICE_TYPE, (const void *)sendDevType, devTypeLen);
if (advId == NON_ADV_ID) {
AssembleNonOptionalTlv(info, boardcastData);
}

View File

@ -124,15 +124,15 @@ int32_t DiscBleGetDeviceName(char *deviceName)
return SOFTBUS_OK;
}
uint8_t DiscBleGetDeviceType(void)
uint16_t DiscBleGetDeviceType(void)
{
char type[DEVICE_TYPE_BUF_LEN] = {0};
uint8_t typeId;
if (LnnGetLocalStrInfo(STRING_KEY_DEV_TYPE, type, DEVICE_TYPE_BUF_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "Get local device type failed.");
return TYPE_UNKNOW_ID;
}
if (LnnConvertDeviceTypeToId(type, (uint16_t *)&typeId) != SOFTBUS_OK) {
uint16_t typeId = 0;
if (LnnConvertDeviceTypeToId(type, &typeId) != SOFTBUS_OK) {
return TYPE_UNKNOW_ID;
}
return typeId;
@ -234,6 +234,19 @@ static int32_t CopyBrAddrValue(DeviceWrapper *device, const unsigned char *src,
return ret;
}
static int32_t ParseDeviceType(DeviceWrapper *device, const unsigned char* data, const uint32_t len)
{
uint8_t recvDevType[DEVICE_TYPE_LEN] = {0};
if (CopyValue(recvDevType, DEVICE_TYPE_LEN, data, len, "TLV_TYPE_DEVICE_TYPE") != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
device->info->devType = recvDevType[0];
if (len == DEVICE_TYPE_LEN) {
device->info->devType = (recvDevType[1] << ONE_BYTE_LENGTH) | recvDevType[0];
}
return SOFTBUS_OK;
}
static int32_t ParseRecvTlvs(DeviceWrapper *device, const unsigned char *data, uint32_t dataLen)
{
uint32_t curLen = POS_TLV + ADV_HEAD_LEN;
@ -252,8 +265,7 @@ static int32_t ParseRecvTlvs(DeviceWrapper *device, const unsigned char *data, u
&data[curLen + 1], len, "TLV_TYPE_DEVICE_ID_HASH");
break;
case TLV_TYPE_DEVICE_TYPE:
ret = CopyValue(&device->info->devType, DEVICE_TYPE_LEN,
&data[curLen + 1], len, "TLV_TYPE_DEVICE_TYPE");
ret = ParseDeviceType(device, &data[curLen + 1], len);
break;
case TLV_TYPE_DEVICE_NAME:
ret = CopyValue(device->info->devName, DISC_MAX_DEVICE_NAME_LEN,
@ -335,4 +347,4 @@ int32_t GetDeviceInfoFromDisAdvData(DeviceWrapper *device, const unsigned char *
int32_t ret = ParseRecvTlvs(device, copyData, advLen + scanRspTlvLen);
SoftBusFree(copyData);
return ret;
}
}