• 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 <cstdio>
13 #include <cstdint>
14 #include <unistd.h>
15 #include <fcntl.h>
16 
17 namespace OHOS {
ForceShrinkAnonFuzzer(const uint8_t * data,size_t size)18 bool ForceShrinkAnonFuzzer(const uint8_t *data, size_t size)
19 {
20     const char *forceShrinkAnon = "/dev/memcg/memory.force_shrink_anon";
21     int fd = open(forceShrinkAnon, O_RDWR);
22     if (fd < 0) {
23         return false;
24     }
25 
26     int ret = write(fd, data, size);
27     if (ret < 0) {
28         printf("%s write fail\n", forceShrinkAnon);
29         close(fd);
30         return false;
31     }
32 
33     close(fd);
34     return true;
35 }
36 } // namespace OHOS
37 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)38 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
39 {
40     OHOS::ForceShrinkAnonFuzzer(data, size);
41     return 0;
42 }
43