• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * SPDX-License-Identifier: GPL-2.0
4  *
5  * Unless required by applicable law or agreed to in writing, software
6  * distributed under the License is distributed on an "AS IS" BASIS,
7  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8  * See the License for the specific language governing permissions and
9  * limitations under the License.
10  */
11 
12 #include <cstddef>
13 #include <fcntl.h>
14 #include <unistd.h>
15 #include <cstdint>
16 #include "memorycommon.h"
17 
18 namespace OHOS {
MemoryFuzzTest(const uint8_t * data,size_t size,const char * pathname)19 bool MemoryFuzzTest(const uint8_t *data, size_t size, const char *pathname)
20 {
21     uint32_t value = 0;
22 
23     int fd = open(pathname, O_RDWR);
24     if (fd < 0) {
25         return false;
26     }
27 
28     int ret = read(fd, &value, sizeof(value));
29     if (ret < 0) {
30         close(fd);
31         return false;
32     }
33 
34     ret = write(fd, data, size);
35     if (ret < 0) {
36         close(fd);
37         return false;
38     }
39 
40     close(fd);
41     return true;
42 }
43 }