1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "writeupdatermsg_fuzzer.h" 17 18#include <array> 19#include <cstddef> 20#include <cstdint> 21#include <cstring> 22#include "log/log.h" 23#include "misc_info/misc_info.h" 24#include "securec.h" 25 26using namespace Updater; 27namespace OHOS { 28 void FuzzWriteUpdaterMsg(const uint8_t* data, size_t size) 29 { 30 UpdateMessage boot; 31 if (memcpy_s(boot.update, MAX_UPDATE_SIZE - 1, reinterpret_cast<const char*>(data), size) != EOK) { 32 return; 33 } 34 ReadUpdaterMiscMsg(boot); 35 const std::string path = "/dev/block/by_name/misc"; 36 WriteUpdaterMessage(path, boot); 37 WriteUpdaterMiscMsg(boot); 38 } 39 void FuzzWriteUpdaterPara() 40 { 41 UpdaterPara boot; 42 WriteUpdaterParaMisc(boot); 43 ReadUpdaterParaMisc(boot); 44 ClearUpdaterParaMisc(); 45 } 46} 47 48/* Fuzzer entry point */ 49extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 50{ 51 /* Run your code on data */ 52 OHOS::FuzzWriteUpdaterMsg(data, size); 53 OHOS::FuzzWriteUpdaterPara(); 54 return 0; 55} 56 57