Coverage Report

Created: 2026-10-31 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl_fuzzer/full_coverage/utility_api.cc
Line
Count
Source
1
/*
2
 * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al.
3
 *
4
 * SPDX-License-Identifier: curl
5
 */
6
7
#include "full_coverage/utility_api.h"
8
9
#include <ctime>
10
11
#include <curl/curl.h>
12
13
namespace full_coverage {
14
namespace {
15
16
/** Replay ordinary formats documented by curl and its date-parser tests. */
17
void ExerciseDates()
18
2
{
19
  // Valid formats and ordinary calendar variants follow
20
  // curl/docs/libcurl/curl_getdate.md. Epoch,
21
  // unsupported-format, calendar-range, and time_t-range examples come from
22
  // curl/tests/libtest/lib517.c. Every input is a short, fixed date string.
23
2
  const char *const dates[] = {
24
2
      "Sun, 06 Nov 1994 08:49:37 GMT",
25
2
      "Sunday, 06-Nov-94 08:49:37 GMT",
26
2
      "Sun Nov  6 08:49:37 1994",
27
2
      "06-Jul-94 08:49:37",
28
2
      "GMT 08:49:37 06-Aug-95 Sunday",
29
2
      "94 6 Oct 08:49:37",
30
2
      "1994 Mar 6",
31
2
      "1994.Feb.6",
32
2
      "Sun/Jun/6/93/GMT",
33
2
      "Mon, 06 Nov 1995 08:49:37 CET",
34
2
      "Tue, 06 Nov 2001 08:49:37 EST",
35
2
      "Sun, 12 Sep 2004 15:05:58 -0700",
36
2
      "Fri, 11 Sep 2009 21:32:11 +0200",
37
2
      "20040912 15:05:58 -0700",
38
2
      "20040911 +0200",
39
2
      "Saturday, May 5 GMT 11:56:27 2035",
40
2
      "Sat, 15-Apr-17 21:01:22 GMT",
41
2
      "Wed, 31 Dec 2008 23:59:60 GMT",
42
2
      "Thu, 01-Jan-1970 00:00:00 GMT",
43
2
      "Thu, 31-Dec-1969 23:59:59 GMT",
44
2
      "IAintNoDateFool",
45
2
      "1994-11-06T08:49:37Z",
46
2
      "Thu, 01-Jan-1499 00:00:00 GMT",
47
2
      "Sun, 06 Nov 1900 08:49:37 GMT",
48
2
      "Sun, 06 Nov 2044 08:49:37 GMT",
49
2
      ""};
50
52
  for(const char *date : dates) {
51
52
    const volatile std::time_t parsed = curl_getdate(date, nullptr);
52
52
    (void)parsed;
53
52
  }
54
2
  const volatile std::time_t missing = curl_getdate(nullptr, nullptr);
55
2
  (void)missing;
56
2
}
57
58
/** Cover compatibility aliases and the explicit binary-length API contract. */
59
void ExerciseEscaping()
60
2
{
61
2
  const char *const strings[] = {
62
2
      "",
63
2
      "data to convert",
64
2
      "a/b?c=d&reserved=+ %#",
65
2
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"};
66
8
  for(const char *text : strings) {
67
8
    char *encoded = curl_escape(text, 0);
68
8
    if(encoded) {
69
8
      curl_free(curl_unescape(encoded, 0));
70
8
      int length = 0;
71
8
      curl_free(curl_easy_unescape(nullptr, encoded, 0, &length));
72
8
    }
73
8
    curl_free(encoded);
74
8
  }
75
76
  // The escaping documentation specifies byte-oriented encoding. Explicit
77
  // lengths preserve an embedded NUL and a non-ASCII byte through decoding.
78
2
  const char binary[] = {'a', '\0', '%', static_cast<char>(0xff)};
79
2
  char *encoded = curl_escape(binary, static_cast<int>(sizeof(binary)));
80
2
  if(encoded) {
81
2
    int length = 0;
82
2
    curl_free(curl_easy_unescape(nullptr, encoded, 0, &length));
83
2
    curl_free(curl_unescape(encoded, 0));
84
2
  }
85
2
  curl_free(encoded);
86
2
  curl_free(curl_unescape("%00%FF%41", 9));
87
88
  // These rejected length values are ordinary API-contract checks from
89
  // curl/tests/libtest/lib1605.c; no memory or operating-system faults occur.
90
2
  curl_free(curl_easy_escape(nullptr, "", -1));
91
2
  int length = 0;
92
2
  curl_free(curl_easy_unescape(nullptr, "%41%41%41%41", -1, &length));
93
2
}
94
95
}  // namespace
96
97
void ExerciseUtilityApiCoverageWithInitializedCurl()
98
2
{
99
  // The returned version string has static storage and must not be freed.
100
2
  const char *volatile version = curl_version();
101
2
  (void)version;
102
2
  ExerciseDates();
103
2
  ExerciseEscaping();
104
2
}
105
106
void ExerciseUtilityApiCoverage()
107
0
{
108
0
  if(curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
109
0
    return;
110
111
0
  ExerciseUtilityApiCoverageWithInitializedCurl();
112
0
  curl_global_cleanup();
113
0
}
114
115
}  // namespace full_coverage