[libc-commits] [libc] [libc] Add a differential fuzzer for inet_aton (PR #200341)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Fri May 29 04:52:55 PDT 2026
================
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Differential fuzz test for llvm-libc inet_aton implementation.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/arpa/inet/inet_aton.h"
+#include <arpa/inet.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ if (size == 0 || data[size - 1] != '\0')
+ return -1;
+
+ struct in_addr ref_addr = {};
+ struct in_addr impl_addr = {};
+ int ref = ::inet_aton(reinterpret_cast<const char *>(data), &ref_addr);
+ int impl = LIBC_NAMESPACE::inet_aton(reinterpret_cast<const char *>(data),
+ &impl_addr);
+
+ if (ref != impl) {
+ fprintf(stderr,
+ "Different result (reference: %d, implementation: %d) for \"%s\"\n",
+ ref, impl, data);
----------------
kaladron wrote:
data here should be cast to const char* as you did above for impl, and it's needed below as well.
I suggest just making a new variable with that once at the top and using it throughout.
https://github.com/llvm/llvm-project/pull/200341
More information about the libc-commits
mailing list