brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · c15649a Raw
39 lines · cpp
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-exception6//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 input17  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 strcpy29    if (dest[i] != src[i]) __builtin_trap();30  }31  // Ensure strcpy null terminates dest32  if (dest[i] != src[i]) __builtin_trap();33 34  delete[] dest;35 36  return 0;37}38 39