1 //===-- strcpy_fuzz.cpp ---------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 /// Fuzzing test for llvm-libc strcpy implementation.
11 //===----------------------------------------------------------------------===//
12 #include "src/string/strcpy.h"
15 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data
, size_t size
) {
18 if (data
[size
- 1] != '\0') return 0;
19 const char *src
= (const char *)data
;
21 char *dest
= new char[size
];
22 if (!dest
) __builtin_trap();
24 LIBC_NAMESPACE::strcpy(dest
, src
);
27 for (i
= 0; src
[i
] != '\0'; i
++) {
28 // Ensure correctness of strcpy
29 if (dest
[i
] != src
[i
]) __builtin_trap();
31 // Ensure strcpy null terminates dest
32 if (dest
[i
] != src
[i
]) __builtin_trap();