[libc-commits] [libc] ed29c68 - [libc] Add a differential fuzzer for inet_aton (#200341)
via libc-commits
libc-commits at lists.llvm.org
Thu Jun 11 03:37:50 PDT 2026
Author: Pavel Labath
Date: 2026-06-11T12:37:46+02:00
New Revision: ed29c68bbdf52f377120817b7a371f5ba641b0d0
URL: https://github.com/llvm/llvm-project/commit/ed29c68bbdf52f377120817b7a371f5ba641b0d0
DIFF: https://github.com/llvm/llvm-project/commit/ed29c68bbdf52f377120817b7a371f5ba641b0d0.diff
LOG: [libc] Add a differential fuzzer for inet_aton (#200341)
Added:
libc/fuzzing/arpa/CMakeLists.txt
libc/fuzzing/arpa/inet/CMakeLists.txt
libc/fuzzing/arpa/inet/inet_aton_differential_fuzz.cpp
Modified:
libc/fuzzing/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/fuzzing/CMakeLists.txt b/libc/fuzzing/CMakeLists.txt
index e2dcecca7f7df..de3ae527b495a 100644
--- a/libc/fuzzing/CMakeLists.txt
+++ b/libc/fuzzing/CMakeLists.txt
@@ -2,6 +2,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer")
add_custom_target(libc-fuzzer)
add_subdirectory(__support)
+add_subdirectory(arpa)
# TODO(#85680): Re-enable math fuzzing after headers are sorted out
add_subdirectory(math)
add_subdirectory(stdlib)
diff --git a/libc/fuzzing/arpa/CMakeLists.txt b/libc/fuzzing/arpa/CMakeLists.txt
new file mode 100644
index 0000000000000..5c89828860ff8
--- /dev/null
+++ b/libc/fuzzing/arpa/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(inet)
diff --git a/libc/fuzzing/arpa/inet/CMakeLists.txt b/libc/fuzzing/arpa/inet/CMakeLists.txt
new file mode 100644
index 0000000000000..0a940799c448d
--- /dev/null
+++ b/libc/fuzzing/arpa/inet/CMakeLists.txt
@@ -0,0 +1,9 @@
+add_libc_fuzzer(
+ inet_aton_
diff erential_fuzz
+ SRCS
+ inet_aton_
diff erential_fuzz.cpp
+ DEPENDS
+ libc.src.__support.CPP.scope
+ libc.src.arpa.inet.inet_aton
+ libc.src.string.memcpy
+)
diff --git a/libc/fuzzing/arpa/inet/inet_aton_
diff erential_fuzz.cpp b/libc/fuzzing/arpa/inet/inet_aton_
diff erential_fuzz.cpp
new file mode 100644
index 0000000000000..9b5006756059e
--- /dev/null
+++ b/libc/fuzzing/arpa/inet/inet_aton_
diff erential_fuzz.cpp
@@ -0,0 +1,50 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/__support/CPP/scope.h"
+#include "src/arpa/inet/inet_aton.h"
+#include "src/string/memcpy.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) {
+ // Create a null-terminated copy of the data
+ char *str = new char[size + 1];
+ LIBC_NAMESPACE::cpp::scope_exit delete_str([&] { delete[] str; });
+ LIBC_NAMESPACE::memcpy(str, data, size);
+ str[size] = '\0';
+
+ struct in_addr ref_addr = {};
+ struct in_addr impl_addr = {};
+ int ref = ::inet_aton(str, &ref_addr);
+ int impl = LIBC_NAMESPACE::inet_aton(str, &impl_addr);
+
+ if (ref != impl) {
+ fprintf(stderr,
+ "Different result (reference: %d, implementation: %d) for \"%s\"\n",
+ ref, impl, str);
+ __builtin_trap();
+ }
+
+ if (ref == 1 && ref_addr.s_addr != impl_addr.s_addr) {
+ fprintf(
+ stderr,
+ "Different address (reference: %x, implementation: %x) for \"%s\"\n",
+ ref_addr.s_addr, impl_addr.s_addr, str);
+ __builtin_trap();
+ }
+
+ return 0;
+}
More information about the libc-commits
mailing list