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