1//===-- strcpy_fuzz.cpp ---------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8///
9/// Fuzzing test for llvm-libc strcpy implementation.
10///
11//===----------------------------------------------------------------------===//
12#include "src/string/strcpy.h"
13#include <stdint.h>
14
15extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
16 // Validate input
17 if (!size) return 0;
18 if (data[size - 1] != '\0') return 0;
19 const char *src = (const char *)data;
20
21 char *dest = new char[size];
22 if (!dest) __builtin_trap();
23
24 LIBC_NAMESPACE::strcpy(dest, src);
25
26 size_t i;
27 for (i = 0; src[i] != '\0'; i++) {
28 // Ensure correctness of strcpy
29 if (dest[i] != src[i]) __builtin_trap();
30 }
31 // Ensure strcpy null terminates dest
32 if (dest[i] != src[i]) __builtin_trap();
33
34 delete[] dest;
35
36 return 0;
37}
38
39

source code of libc/fuzzing/string/strcpy_fuzz.cpp