!2502 bugfix: discovery fuzz test crash as random bytes is not trailing \0

Merge pull request !2502 from waibozie/bugfix_discovery_fuzz_fail
This commit is contained in:
openharmony_ci 2022-10-09 13:09:36 +00:00 committed by Gitee
commit 84637c0f6b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 80 additions and 8 deletions

View File

@ -22,6 +22,7 @@ ohos_fuzztest("PublishServiceFuzzTest") {
module_out_path = "dsoftbus/discovery"
fuzz_config_file = "//foundation/communication/dsoftbus/tests/sdk/discovery/fuzztest/publishservice_fuzzer"
include_dirs = [
"//foundation/communication/dsoftbus/adapter/common/include",
"//foundation/communication/dsoftbus/core/common/inner_communication",
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
@ -39,7 +40,10 @@ ohos_fuzztest("PublishServiceFuzzTest") {
]
sources = [ "publishservice_fuzzer.cpp" ]
deps = [ "//foundation/communication/dsoftbus/sdk:softbus_client" ]
deps = [
"//foundation/communication/dsoftbus/adapter:softbus_adapter",
"//foundation/communication/dsoftbus/sdk:softbus_client",
]
external_deps = [ "c_utils:utils" ]
}

View File

@ -14,9 +14,13 @@
*/
#include "publishservice_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include <securec.h>
#include "discovery_service.h"
#include "softbus_adapter_mem.h"
namespace OHOS {
static int g_publishId = 0;
@ -58,7 +62,17 @@ void PublishServiceTest(const uint8_t* data, size_t size)
return;
}
PublishService((const char*)data, &testInfo, &g_publishCb);
// add trailing '\0'
uint8_t *pkgName = (uint8_t *)SoftBusCalloc((size + 1) * sizeof(uint8_t));
if (pkgName == nullptr) {
return;
}
if (memcpy_s(pkgName, size + 1, data, size) != EOK) {
SoftBusFree(pkgName);
return;
}
PublishService((const char*)pkgName, &testInfo, &g_publishCb);
SoftBusFree(pkgName);
}
} // namespace OHOS

View File

@ -22,6 +22,7 @@ ohos_fuzztest("StartDiscoveryFuzzTest") {
module_out_path = "dsoftbus/discovery"
fuzz_config_file = "//foundation/communication/dsoftbus/tests/sdk/discovery/fuzztest/startdiscovery_fuzzer"
include_dirs = [
"//foundation/communication/dsoftbus/adapter/common/include",
"//foundation/communication/dsoftbus/core/common/inner_communication",
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
@ -39,7 +40,10 @@ ohos_fuzztest("StartDiscoveryFuzzTest") {
]
sources = [ "startdiscovery_fuzzer.cpp" ]
deps = [ "//foundation/communication/dsoftbus/sdk:softbus_client" ]
deps = [
"//foundation/communication/dsoftbus/adapter:softbus_adapter",
"//foundation/communication/dsoftbus/sdk:softbus_client",
]
external_deps = [ "c_utils:utils" ]
}

View File

@ -14,9 +14,13 @@
*/
#include "startdiscovery_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include <securec.h>
#include "discovery_service.h"
#include "softbus_adapter_mem.h"
namespace OHOS {
static int g_subscribeId = 0;
@ -64,7 +68,17 @@ void StartDiscoveryTest(const uint8_t* data, size_t size)
return;
}
StartDiscovery((const char*)data, &testInfo, &g_subscribeCb);
// add trailing '\0'
uint8_t *pkgName = (uint8_t *)SoftBusCalloc((size + 1) * sizeof(uint8_t));
if (pkgName == nullptr) {
return;
}
if (memcpy_s(pkgName, size + 1, data, size) != EOK) {
SoftBusFree(pkgName);
return;
}
StartDiscovery((const char*)pkgName, &testInfo, &g_subscribeCb);
SoftBusFree(pkgName);
}
} // namespace OHOS

View File

@ -22,6 +22,7 @@ ohos_fuzztest("StopDiscoveryFuzzTest") {
module_out_path = "dsoftbus/discovery"
fuzz_config_file = "//foundation/communication/dsoftbus/tests/sdk/discovery/fuzztest/stopdiscovery_fuzzer"
include_dirs = [
"//foundation/communication/dsoftbus/adapter/common/include",
"//foundation/communication/dsoftbus/core/common/inner_communication",
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
@ -39,7 +40,10 @@ ohos_fuzztest("StopDiscoveryFuzzTest") {
]
sources = [ "stopdiscovery_fuzzer.cpp" ]
deps = [ "//foundation/communication/dsoftbus/sdk:softbus_client" ]
deps = [
"//foundation/communication/dsoftbus/adapter:softbus_adapter",
"//foundation/communication/dsoftbus/sdk:softbus_client",
]
external_deps = [ "c_utils:utils" ]
}

View File

@ -14,9 +14,13 @@
*/
#include "stopdiscovery_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include <securec.h>
#include "discovery_service.h"
#include "softbus_adapter_mem.h"
namespace OHOS {
static int g_subscribeId = 0;
@ -49,7 +53,17 @@ void StopDiscoveryTest(const uint8_t* data, size_t size)
return;
}
StopDiscovery((const char*)data, testInfo.subscribeId);
// add trailing '\0'
uint8_t *pkgName = (uint8_t *)SoftBusCalloc((size + 1) * sizeof(uint8_t));
if (pkgName == nullptr) {
return;
}
if (memcpy_s(pkgName, size + 1, data, size) != EOK) {
SoftBusFree(pkgName);
return;
}
StopDiscovery((const char*)pkgName, testInfo.subscribeId);
SoftBusFree(pkgName);
}
} // namespace OHOS

View File

@ -22,6 +22,7 @@ ohos_fuzztest("UnPublishServiceFuzzTest") {
module_out_path = "dsoftbus/discovery"
fuzz_config_file = "//foundation/communication/dsoftbus/tests/sdk/discovery/fuzztest/unpublishservice_fuzzer"
include_dirs = [
"//foundation/communication/dsoftbus/adapter/common/include",
"//foundation/communication/dsoftbus/core/common/inner_communication",
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
@ -39,7 +40,10 @@ ohos_fuzztest("UnPublishServiceFuzzTest") {
]
sources = [ "unpublishservice_fuzzer.cpp" ]
deps = [ "//foundation/communication/dsoftbus/sdk:softbus_client" ]
deps = [
"//foundation/communication/dsoftbus/adapter:softbus_adapter",
"//foundation/communication/dsoftbus/sdk:softbus_client",
]
external_deps = [ "c_utils:utils" ]
}

View File

@ -14,9 +14,13 @@
*/
#include "unpublishservice_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include <securec.h>
#include "discovery_service.h"
#include "softbus_adapter_mem.h"
namespace OHOS {
static int g_publishId = 0;
@ -47,7 +51,17 @@ void UnPublishServiceTest(const uint8_t* data, size_t size)
return;
}
UnPublishService((const char*)data, testInfo.publishId);
// add trailing '\0'
uint8_t *pkgName = (uint8_t *)SoftBusCalloc((size + 1) * sizeof(uint8_t));
if (pkgName == nullptr) {
return;
}
if (memcpy_s(pkgName, size + 1, data, size) != EOK) {
SoftBusFree(pkgName);
return;
}
UnPublishService((const char*)pkgName, testInfo.publishId);
SoftBusFree(pkgName);
}
} // namespace OHOS