Coverage Report

Created: 2025-09-27 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/ext/uri/uriparser/src/UriSetHostRegName.c
Line
Count
Source
1
/*
2
 * uriparser - RFC 3986 URI parsing library
3
 *
4
 * Copyright (C) 2025, Sebastian Pipping <sebastian@pipping.org>
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source  and binary forms, with or without
8
 * modification, are permitted provided  that the following conditions
9
 * are met:
10
 *
11
 *     1. Redistributions  of  source  code   must  retain  the  above
12
 *        copyright notice, this list  of conditions and the following
13
 *        disclaimer.
14
 *
15
 *     2. Redistributions  in binary  form  must  reproduce the  above
16
 *        copyright notice, this list  of conditions and the following
17
 *        disclaimer  in  the  documentation  and/or  other  materials
18
 *        provided with the distribution.
19
 *
20
 *     3. Neither the  name of the  copyright holder nor the  names of
21
 *        its contributors may be used  to endorse or promote products
22
 *        derived from  this software  without specific  prior written
23
 *        permission.
24
 *
25
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
 * "AS IS" AND  ANY EXPRESS OR IMPLIED WARRANTIES,  INCLUDING, BUT NOT
27
 * LIMITED TO,  THE IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS
28
 * FOR  A  PARTICULAR  PURPOSE  ARE  DISCLAIMED.  IN  NO  EVENT  SHALL
29
 * THE  COPYRIGHT HOLDER  OR CONTRIBUTORS  BE LIABLE  FOR ANY  DIRECT,
30
 * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
 * (INCLUDING, BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS OR
32
 * SERVICES; LOSS OF USE, DATA,  OR PROFITS; OR BUSINESS INTERRUPTION)
33
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34
 * STRICT  LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE  OR  OTHERWISE)
35
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36
 * OF THE POSSIBILITY OF SUCH DAMAGE.
37
 */
38
39
/* What encodings are enabled? */
40
#include <uriparser/UriDefsConfig.h>
41
#if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE))
42
/* Include SELF twice */
43
# ifdef URI_ENABLE_ANSI
44
#  define URI_PASS_ANSI 1
45
#  include "UriSetHostRegName.c"
46
#  undef URI_PASS_ANSI
47
# endif
48
# ifdef URI_ENABLE_UNICODE
49
#  define URI_PASS_UNICODE 1
50
#  include "UriSetHostRegName.c"
51
#  undef URI_PASS_UNICODE
52
# endif
53
#else
54
# ifdef URI_PASS_ANSI
55
#  include <uriparser/UriDefsAnsi.h>
56
# else
57
#  include <uriparser/UriDefsUnicode.h>
58
#  include <wchar.h>
59
# endif
60
61
62
63
#ifndef URI_DOXYGEN
64
# include <uriparser/Uri.h>
65
# include "UriMemory.h"
66
# include "UriSetHostBase.h"
67
# include "UriSetHostCommon.h"
68
#endif
69
70
71
72
#define URI_SET_DIGIT \
73
0
       _UT('0'): \
74
0
  case _UT('1'): \
75
0
  case _UT('2'): \
76
0
  case _UT('3'): \
77
0
  case _UT('4'): \
78
0
  case _UT('5'): \
79
0
  case _UT('6'): \
80
0
  case _UT('7'): \
81
0
  case _UT('8'): \
82
0
  case _UT('9')
83
84
85
86
#define URI_SET_HEX_LETTER_UPPER \
87
0
       _UT('A'): \
88
0
  case _UT('B'): \
89
0
  case _UT('C'): \
90
0
  case _UT('D'): \
91
0
  case _UT('E'): \
92
0
  case _UT('F')
93
94
95
96
#define URI_SET_HEX_LETTER_LOWER \
97
0
       _UT('a'): \
98
0
  case _UT('b'): \
99
0
  case _UT('c'): \
100
0
  case _UT('d'): \
101
0
  case _UT('e'): \
102
0
  case _UT('f')
103
104
105
106
#define URI_SET_HEXDIG \
107
0
  URI_SET_DIGIT: \
108
0
  case URI_SET_HEX_LETTER_UPPER: \
109
0
  case URI_SET_HEX_LETTER_LOWER
110
111
112
113
#define URI_SET_ALPHA \
114
0
  URI_SET_HEX_LETTER_UPPER: \
115
0
  case URI_SET_HEX_LETTER_LOWER: \
116
0
  case _UT('g'): \
117
0
  case _UT('G'): \
118
0
  case _UT('h'): \
119
0
  case _UT('H'): \
120
0
  case _UT('i'): \
121
0
  case _UT('I'): \
122
0
  case _UT('j'): \
123
0
  case _UT('J'): \
124
0
  case _UT('k'): \
125
0
  case _UT('K'): \
126
0
  case _UT('l'): \
127
0
  case _UT('L'): \
128
0
  case _UT('m'): \
129
0
  case _UT('M'): \
130
0
  case _UT('n'): \
131
0
  case _UT('N'): \
132
0
  case _UT('o'): \
133
0
  case _UT('O'): \
134
0
  case _UT('p'): \
135
0
  case _UT('P'): \
136
0
  case _UT('q'): \
137
0
  case _UT('Q'): \
138
0
  case _UT('r'): \
139
0
  case _UT('R'): \
140
0
  case _UT('s'): \
141
0
  case _UT('S'): \
142
0
  case _UT('t'): \
143
0
  case _UT('T'): \
144
0
  case _UT('u'): \
145
0
  case _UT('U'): \
146
0
  case _UT('v'): \
147
0
  case _UT('V'): \
148
0
  case _UT('w'): \
149
0
  case _UT('W'): \
150
0
  case _UT('x'): \
151
0
  case _UT('X'): \
152
0
  case _UT('y'): \
153
0
  case _UT('Y'): \
154
0
  case _UT('z'): \
155
0
  case _UT('Z')
156
157
158
159
#define URI_SET_SUB_DELIMS \
160
0
       _UT('!'): \
161
0
  case _UT('$'): \
162
0
  case _UT('&'): \
163
0
  case _UT('\''): \
164
0
  case _UT('('): \
165
0
  case _UT(')'): \
166
0
  case _UT('*'): \
167
0
  case _UT('+'): \
168
0
  case _UT(','): \
169
0
  case _UT(';'): \
170
0
  case _UT('=')
171
172
173
174
#define URI_SET_UNRESERVED \
175
0
  URI_SET_ALPHA: \
176
0
  case URI_SET_DIGIT: \
177
0
  case _UT('-'): \
178
0
  case _UT('.'): \
179
0
  case _UT('_'): \
180
0
  case _UT('~')
181
182
183
184
0
UriBool URI_FUNC(IsWellFormedHostRegName)(const URI_CHAR * first, const URI_CHAR * afterLast) {
185
0
  if ((first == NULL) || (afterLast == NULL)) {
186
0
    return URI_FALSE;
187
0
  }
188
189
  /* reg-name = *( unreserved / pct-encoded / sub-delims ) */
190
0
  while (first < afterLast) {
191
0
    switch (first[0]) {
192
0
      case URI_SET_UNRESERVED:
193
0
        break;
194
195
      /* pct-encoded */
196
0
      case _UT('%'):
197
0
        if (afterLast - first < 3) {
198
0
          return URI_FALSE;
199
0
        }
200
0
        switch (first[1]) {
201
0
          case URI_SET_HEXDIG:
202
0
            break;
203
0
          default:
204
0
            return URI_FALSE;
205
0
        }
206
0
        switch (first[2]) {
207
0
          case URI_SET_HEXDIG:
208
0
            break;
209
0
          default:
210
0
            return URI_FALSE;
211
0
        }
212
0
        first += 2;
213
0
        break;
214
215
0
      case URI_SET_SUB_DELIMS:
216
0
        break;
217
218
0
      default:
219
0
        return URI_FALSE;
220
0
    }
221
222
0
    first++;
223
0
  }
224
0
  return URI_TRUE;
225
0
}
Unexecuted instantiation: uriIsWellFormedHostRegNameA
Unexecuted instantiation: uriIsWellFormedHostRegNameW
226
227
228
229
int URI_FUNC(SetHostRegNameMm)(URI_TYPE(Uri) * uri,
230
    const URI_CHAR * first,
231
    const URI_CHAR * afterLast,
232
0
    UriMemoryManager * memory) {
233
0
  return URI_FUNC(InternalSetHostMm)(uri, URI_HOST_TYPE_REGNAME, first, afterLast, memory);
234
0
}
Unexecuted instantiation: uriSetHostRegNameMmA
Unexecuted instantiation: uriSetHostRegNameMmW
235
236
237
238
int URI_FUNC(SetHostRegName)(URI_TYPE(Uri) * uri,
239
    const URI_CHAR * first,
240
0
    const URI_CHAR * afterLast) {
241
0
  return URI_FUNC(SetHostRegNameMm)(uri, first, afterLast, NULL);
242
0
}
Unexecuted instantiation: uriSetHostRegNameA
Unexecuted instantiation: uriSetHostRegNameW
243
244
245
246
#endif