curl-fuzzer C++ reference
Loading...
Searching...
No Matches
api_coverage_probes.cc
1/*
2 * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al.
3 *
4 * SPDX-License-Identifier: curl
5 */
6
8
9#include <curl/curl.h>
10
11#include "full_coverage/dynamic_formatting.h"
12#include "full_coverage/public_api.h"
13#include "full_coverage/utility_api.h"
14#include "proto_fuzzer/allocation_fault_injection.h"
16
17namespace proto_fuzzer {
18namespace {
19
21class DeferredCurlGlobalReference final {
22 public:
23 DeferredCurlGlobalReference() : initialized_(curl_global_init(CURL_GLOBAL_ALL) == CURLE_OK) {}
24
25 ~DeferredCurlGlobalReference() {
26 if (initialized_) {
27 // Drop this probe's public reference, then ask the registered owner to
28 // release its own base reference. This destructor was registered from
29 // LLVMFuzzerInitialize, so final resolver/TLS cleanup runs before LLVM's
30 // profile writer. The owner's later destructor is then a no-op.
31 curl_global_cleanup();
32 FinalizeRegisteredCurlGlobalLifecyclesForExit();
33 }
34 }
35
36 DeferredCurlGlobalReference(const DeferredCurlGlobalReference&) = delete;
37 DeferredCurlGlobalReference& operator=(const DeferredCurlGlobalReference&) = delete;
38
39 private:
40 bool initialized_;
41};
42
43} // namespace
44
53void RunApiCoverageProbesOnce() {
54 // This function-local lifetime begins after the proto runtime's static
55 // bootstrap, so its destructor can finalize curl before the bootstrap's
56 // idempotent destructor and LLVM's profile write.
57 static const DeferredCurlGlobalReference global_reference;
58 static const bool completed = [] {
59 // These are harness-owned deterministic allocations, not part of a
60 // Scenario's fault plan. The initialization hook normally runs before a
61 // plan can be armed; suppression also makes the callback fallback safe.
63 full_coverage::ExercisePublicApiCoverageWithInitializedCurl();
64 full_coverage::ExerciseUtilityApiCoverageWithInitializedCurl();
65 full_coverage::ExerciseDynamicFormattingCoverage();
66 return true;
67 }();
68 (void)global_reference;
69 (void)completed;
70}
71
72} // namespace proto_fuzzer
Process-once curl API probes for the structured API target.
Exclude a narrow harness-only operation from the allocation-failure plan.
Process-wide libcurl initialization and final cleanup.