!1493 fix:code coverage of fuzz test

Merge pull request !1493 from yue/master
This commit is contained in:
openharmony_ci 2024-10-30 00:06:53 +00:00 committed by Gitee
commit cc298ac979
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 20 additions and 5 deletions

View File

@ -120,4 +120,19 @@ static inline bool GenerateString(std::string &value)
return DataGenerator::GetInstance().ReadString(value);
}
static inline bool GenerateStringByLength(std::string &value, size_t length = 0)
{
size_t readAbleSize = DataGenerator::GetInstance().GetReadableBytes();
if (length == 0 || length > readAbleSize) {
length = readAbleSize;
}
const char *bufData = reinterpret_cast<const char *>(DataGenerator::GetInstance().ReadBuffer(length));
if (bufData == nullptr) {
return false;
}
value = std::string(bufData, length);
return true;
}
#endif // FUZZ_DATA_GENERATOR_H

View File

@ -33,7 +33,7 @@ namespace OHOS {
int32_t listenFd;
std::string deviceId;
if (!GenerateUint32(pid) || !GenerateUint32(uid) || !GenerateUint32(tokenId) || !GenerateInt32(listenFd) ||
!GenerateUint64(stubIndex) || !GenerateString(deviceId)) {
!GenerateUint64(stubIndex) || !GenerateStringByLength(deviceId)) {
return false;
}
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
@ -56,7 +56,7 @@ namespace OHOS {
int32_t listenFd;
std::string deviceId;
if (!GenerateUint32(pid) || !GenerateUint32(uid) || !GenerateUint32(tokenId) || !GenerateInt32(listenFd) ||
!GenerateString(deviceId)) {
!GenerateStringByLength(deviceId)) {
return false;
}
IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
@ -828,7 +828,7 @@ namespace OHOS {
sptr<IRemoteObject> remoteObj = new IPCObjectProxy(0, u"proxyTest", 0);
IRemoteObject *stub = remoteObj.GetRefPtr();
if (!GenerateInt32(pid) || !GenerateInt32(uid) || !GenerateUint32(tokenId) ||
!GenerateString(deviceId) || !GenerateInt32(socketId)) {
!GenerateInt32(socketId) || !GenerateStringByLength(deviceId)) {
return false;
}
current->QueryCommAuthInfo(pid, uid, tokenId, deviceId);
@ -853,7 +853,7 @@ namespace OHOS {
sptr<IRemoteObject> remoteObj = new IPCObjectProxy(0, u"proxyTest", 0);
IRemoteObject *stub = remoteObj.GetRefPtr();
if (!GenerateInt32(pid) || !GenerateInt32(uid) || !GenerateUint32(tokenId) ||
!GenerateString(deviceId) || !GenerateInt32(socketId)) {
!GenerateInt32(socketId) || !GenerateStringByLength(deviceId)) {
return false;
}
current->AttachCommAuthInfo(stub, pid, uid, tokenId, deviceId);
@ -875,7 +875,7 @@ namespace OHOS {
sptr<IRemoteObject> remoteObj = new IPCObjectProxy(0, u"proxyTest", 0);
IRemoteObject *stub = remoteObj.GetRefPtr();
if (!GenerateInt32(pid) || !GenerateInt32(uid) || !GenerateUint32(tokenId) ||
!GenerateString(deviceId) || !GenerateInt32(socketId)) {
!GenerateInt32(socketId) || !GenerateStringByLength(deviceId)) {
return false;
}
current->AttachCommAuthInfo(stub, pid, uid, tokenId, deviceId);