1 /*
2 * Copyright (c) 2025 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 #include "mountonewithfstabfile_fuzzer.h"
16 #include "securec.h"
17 #include <sys/socket.h>
18 #include <unistd.h>
19 #include <memory>
20 #include "fs_manager.h"
21 #include <string>
22
23 namespace OHOS {
FuzzMountOneWithFstabFile(const uint8_t * data,size_t size)24 bool FuzzMountOneWithFstabFile(const uint8_t* data, size_t size)
25 {
26 char fstabPath[] = "/tmp/fuzz_fstab_1";
27 int fd = mkstemp(fstabPath);
28 if (fd < 0) {
29 return false;
30 }
31
32 std::string str(reinterpret_cast<const char*>(data), size);
33
34 int ret = MountOneWithFstabFile(fstabPath, str.c_str(), false);
35 unlink(fstabPath);
36 if (ret == 0) {
37 return true;
38 }
39 return false;
40 }
41 }
42
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)43 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
44 {
45 OHOS::FuzzMountOneWithFstabFile(data, size);
46 return 0;
47 }