未验证 提交 1d70b1f7 编写于 作者: O openharmony_ci 提交者: Gitee

!1097 解决fuzztest用例未对测试输入处理的问题

Merge pull request !1097 from cheng_jinsong/master_cc_fuzz
......@@ -14,13 +14,15 @@
*/
#include "doreboot_fuzzer.h"
#include<string>
#include "init_reboot.h"
namespace OHOS {
bool FuzzDoReboot(const uint8_t* data, size_t size)
{
bool result = false;
if (!DoReboot(reinterpret_cast<const char*>(data))) {
std::string str(reinterpret_cast<const char*>(data), size);
if (!DoReboot(str.c_str())) {
result = true;
}
return result;
......
......@@ -14,13 +14,19 @@
*/
#include "getcontrolfile_fuzzer.h"
#include <string>
#include <climits>
#include "init_file.h"
namespace OHOS {
bool FuzzGetControlFile(const uint8_t* data, size_t size)
{
bool result = false;
if (!GetControlFile(reinterpret_cast<const char*>(data))) {
if (size > PATH_MAX) {
return true;
}
std::string str(reinterpret_cast<const char*>(data), size);
if (!GetControlFile(str.c_str())) {
result = true;
}
return result;
......
......@@ -14,13 +14,15 @@
*/
#include "getcontrolsocket_fuzzer.h"
#include <string>
#include "init_socket.h"
namespace OHOS {
bool FuzzGetControlSocket(const uint8_t* data, size_t size)
{
bool result = false;
if (!GetControlSocket(reinterpret_cast<const char*>(data))) {
std::string str(reinterpret_cast<const char*>(data), size);
if (!GetControlSocket(str.c_str())) {
result = true;
}
return result;
......
......@@ -14,13 +14,15 @@
*/
#include "servicecontrolstart_fuzzer.h"
#include<string>
#include "service_control.h"
namespace OHOS {
bool FuzzServiceControlStart(const uint8_t* data, size_t size)
{
bool result = false;
if (!ServiceControl(reinterpret_cast<const char*>(data), START)) {
std::string str(reinterpret_cast<const char*>(data), size);
if (!ServiceControl(str.c_str(), START)) {
result = true;
}
return result;
......
......@@ -14,13 +14,15 @@
*/
#include "servicecontrolstop_fuzzer.h"
#include <string>
#include "service_control.h"
namespace OHOS {
bool FuzzServiceControlStop(const uint8_t* data, size_t size)
{
bool result = false;
if (!ServiceControl(reinterpret_cast<const char*>(data), STOP)) {
std::string str(reinterpret_cast<const char*>(data), size);
if (!ServiceControl(str.c_str(), STOP)) {
result = true;
}
return result;
......
......@@ -14,6 +14,7 @@
*/
#include "systemdumpparameters_fuzzer.h"
#include <string>
#include "init_param.h"
#include "fuzz_utils.h"
......@@ -21,7 +22,8 @@ namespace OHOS {
bool FuzzSystemDumpParameters(const uint8_t* data, size_t size)
{
CloseStdout();
int verbose = atoi(reinterpret_cast<char *>(const_cast<uint8_t *>(data)));
std::string str(reinterpret_cast<const char*>(data), size);
int verbose = atoi(str.c_str());
SystemDumpParameters(verbose);
return true;
}
......
......@@ -14,6 +14,7 @@
*/
#include "systemfindparameter_fuzzer.h"
#include<string>
#include "init_param.h"
static ParamHandle handle;
......@@ -22,7 +23,8 @@ namespace OHOS {
bool FuzzSystemFindParameter(const uint8_t* data, size_t size)
{
bool result = false;
if (!SystemFindParameter(reinterpret_cast<const char*>(data), &handle)) {
std::string str(reinterpret_cast<const char*>(data), size);
if (!SystemFindParameter(str.c_str(), &handle)) {
result = true;
}
return result;
......
......@@ -14,6 +14,7 @@
*/
#include "systemgetparameter_fuzzer.h"
#include<string>
#include "init_param.h"
......@@ -23,7 +24,8 @@ namespace OHOS {
bool result = false;
char buffer[PARAM_CONST_VALUE_LEN_MAX] = {0};
uint32_t len = PARAM_CONST_VALUE_LEN_MAX;
if (!SystemGetParameter(reinterpret_cast<const char*>(data), buffer, &len)) {
std::string str(reinterpret_cast<const char*>(data), size);
if (!SystemGetParameter(str.c_str(), buffer, &len)) {
result = true;
}
return result;
......
......@@ -14,6 +14,7 @@
*/
#include "systemgetparametercommitid_fuzzer.h"
#include <string>
#include "init_param.h"
#include "fuzz_utils.h"
......@@ -23,7 +24,8 @@ namespace OHOS {
bool result = false;
uint32_t commitId = 0;
char *rest = nullptr;
ParamHandle handle = (ParamHandle)strtoul(reinterpret_cast<char *>(const_cast<uint8_t *>(data)), &rest, BASE);
std::string str(reinterpret_cast<const char*>(data), size);
ParamHandle handle = (ParamHandle)strtoul(str.c_str(), &rest, BASE);
if (!SystemGetParameterCommitId(handle, &commitId)) {
result = true;
}
......
......@@ -14,6 +14,7 @@
*/
#include "systemgetparametername_fuzzer.h"
#include <string>
#include "init_param.h"
#include "fuzz_utils.h"
......@@ -23,7 +24,8 @@ namespace OHOS {
bool result = false;
char buffer[PARAM_NAME_LEN_MAX] = {0};
char *rest = nullptr;
ParamHandle handle = (ParamHandle)strtoul(reinterpret_cast<char *>(const_cast<uint8_t *>(data)), &rest, BASE);
std::string str(reinterpret_cast<const char*>(data), size);
ParamHandle handle = (ParamHandle)strtoul(str.c_str(), &rest, BASE);
if (!SystemGetParameterName(handle, buffer, PARAM_NAME_LEN_MAX)) {
result = true;
}
......
......@@ -14,6 +14,7 @@
*/
#include "systemgetparametervalue_fuzzer.h"
#include <string>
#include "init_param.h"
#include "fuzz_utils.h"
......@@ -24,7 +25,8 @@ namespace OHOS {
char buffer[PARAM_CONST_VALUE_LEN_MAX] = {0};
uint32_t len = PARAM_CONST_VALUE_LEN_MAX;
char *rest = nullptr;
ParamHandle handle = (ParamHandle)strtoul(reinterpret_cast<char *>(const_cast<uint8_t *>(data)), &rest, BASE);
std::string str(reinterpret_cast<const char*>(data), size);
ParamHandle handle = (ParamHandle)strtoul(str.c_str(), &rest, BASE);
if (!SystemGetParameterValue(handle, buffer, &len)) {
result = true;
}
......
......@@ -14,13 +14,15 @@
*/
#include "systemsetparameter_fuzzer.h"
#include <string>
#include "init_param.h"
namespace OHOS {
bool FuzzSystemSetParameter(const uint8_t* data, size_t size)
{
bool result = false;
if (!SystemSetParameter(reinterpret_cast<const char*>(data), reinterpret_cast<const char*>(data))) {
std::string str(reinterpret_cast<const char*>(data), size);
if (!SystemSetParameter(str.c_str(), str.c_str())) {
result = true;
}
return result;
......
......@@ -15,6 +15,7 @@
#include "systemtraversalparameter_fuzzer.h"
#include <string>
#include "fuzz_utils.h"
#include "init.h"
#include "securec.h"
......@@ -42,12 +43,16 @@ namespace OHOS {
if (size <= 0) {
return false;
}
if (size > PARAM_CONST_VALUE_LEN_MAX + PARAM_NAME_LEN_MAX) {
return true;
}
cookie->data = static_cast<char *>(malloc(size));
if (cookie->data == nullptr) {
return true;
}
cookie->size = size;
int ret = memcpy_s(cookie->data, size, data, size);
std::string str(reinterpret_cast<const char*>(data), size - 1);
int ret = memcpy_s(cookie->data, size, str.c_str(), size);
if (ret != EOK) {
return false;
}
......
......@@ -14,13 +14,15 @@
*/
#include "systemwaitparameter_fuzzer.h"
#include <string>
#include "init_param.h"
namespace OHOS {
bool FuzzSystemWaitParameter(const uint8_t* data, size_t size)
{
bool result = false;
if (!SystemWaitParameter(reinterpret_cast<const char*>(data), reinterpret_cast<const char*>(data), 1)) {
std::string str(reinterpret_cast<const char*>(data), size);
if (!SystemWaitParameter(str.c_str(), str.c_str(), 1)) {
result = true;
}
return result;
......
......@@ -13,6 +13,7 @@
* limitations under the License.
*/
#include<string>
#include "systemwatchparameter_fuzzer.h"
#include "init.h"
......@@ -31,7 +32,8 @@ namespace OHOS {
bool FuzzSystemWatchParameter(const uint8_t* data, size_t size)
{
bool result = false;
if (!SystemWatchParameter(reinterpret_cast<const char*>(data), HandleParamChange, NULL)) {
std::string str(reinterpret_cast<const char*>(data), size);
if (!SystemWatchParameter(str.c_str(), HandleParamChange, NULL)) {
result = true;
}
return result;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册