Coverage Report

Created: 2025-06-13 06:43

/src/php-src/ext/pcre/pcre2lib/pcre2_config.c
Line
Count
Source (jump to first uncovered line)
1
/*************************************************
2
*      Perl-Compatible Regular Expressions       *
3
*************************************************/
4
5
/* PCRE is a library of functions to support regular expressions whose syntax
6
and semantics are as close as possible to those of the Perl 5 language.
7
8
                       Written by Philip Hazel
9
     Original API code Copyright (c) 1997-2012 University of Cambridge
10
          New API code Copyright (c) 2016-2020 University of Cambridge
11
12
-----------------------------------------------------------------------------
13
Redistribution and use in source and binary forms, with or without
14
modification, are permitted provided that the following conditions are met:
15
16
    * Redistributions of source code must retain the above copyright notice,
17
      this list of conditions and the following disclaimer.
18
19
    * Redistributions in binary form must reproduce the above copyright
20
      notice, this list of conditions and the following disclaimer in the
21
      documentation and/or other materials provided with the distribution.
22
23
    * Neither the name of the University of Cambridge nor the names of its
24
      contributors may be used to endorse or promote products derived from
25
      this software without specific prior written permission.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
POSSIBILITY OF SUCH DAMAGE.
38
-----------------------------------------------------------------------------
39
*/
40
41
#ifdef HAVE_CONFIG_H
42
#include "config.h"
43
#endif
44
45
/* Save the configured link size, which is in bytes. In 16-bit and 32-bit modes
46
its value gets changed by pcre2_intmodedep.h (included by pcre2_internal.h) to
47
be in code units. */
48
49
static int configured_link_size = LINK_SIZE;
50
51
#include "pcre2_internal.h"
52
53
/* These macros are the standard way of turning unquoted text into C strings.
54
They allow macros like PCRE2_MAJOR to be defined without quotes, which is
55
convenient for user programs that want to test their values. */
56
57
0
#define STRING(a)  # a
58
84
#define XSTRING(s) STRING(s)
59
60
61
/*************************************************
62
* Return info about what features are configured *
63
*************************************************/
64
65
/* If where is NULL, the length of memory required is returned.
66
67
Arguments:
68
  what             what information is required
69
  where            where to put the information
70
71
Returns:           0 if a numerical value is returned
72
                   >= 0 if a string value
73
                   PCRE2_ERROR_BADOPTION if "where" not recognized
74
                     or JIT target requested when JIT not enabled
75
*/
76
77
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
78
pcre2_config(uint32_t what, void *where)
79
52
{
80
52
if (where == NULL)  /* Requests a length */
81
26
  {
82
26
  switch(what)
83
26
    {
84
0
    default:
85
0
    return PCRE2_ERROR_BADOPTION;
86
87
0
    case PCRE2_CONFIG_BSR:
88
0
    case PCRE2_CONFIG_COMPILED_WIDTHS:
89
0
    case PCRE2_CONFIG_DEPTHLIMIT:
90
0
    case PCRE2_CONFIG_HEAPLIMIT:
91
0
    case PCRE2_CONFIG_JIT:
92
0
    case PCRE2_CONFIG_LINKSIZE:
93
0
    case PCRE2_CONFIG_MATCHLIMIT:
94
0
    case PCRE2_CONFIG_NEVER_BACKSLASH_C:
95
0
    case PCRE2_CONFIG_NEWLINE:
96
0
    case PCRE2_CONFIG_PARENSLIMIT:
97
0
    case PCRE2_CONFIG_STACKRECURSE:    /* Obsolete */
98
0
    case PCRE2_CONFIG_TABLES_LENGTH:
99
0
    case PCRE2_CONFIG_UNICODE:
100
0
    return sizeof(uint32_t);
101
102
    /* These are handled below */
103
104
0
    case PCRE2_CONFIG_JITTARGET:
105
5
    case PCRE2_CONFIG_UNICODE_VERSION:
106
26
    case PCRE2_CONFIG_VERSION:
107
26
    break;
108
26
    }
109
26
  }
110
111
52
switch (what)
112
52
  {
113
0
  default:
114
0
  return PCRE2_ERROR_BADOPTION;
115
116
0
  case PCRE2_CONFIG_BSR:
117
#ifdef BSR_ANYCRLF
118
  *((uint32_t *)where) = PCRE2_BSR_ANYCRLF;
119
#else
120
0
  *((uint32_t *)where) = PCRE2_BSR_UNICODE;
121
0
#endif
122
0
  break;
123
124
0
  case PCRE2_CONFIG_COMPILED_WIDTHS:
125
0
  *((uint32_t *)where) = 0
126
0
#ifdef SUPPORT_PCRE2_8
127
0
  + 1
128
0
#endif
129
#ifdef SUPPORT_PCRE2_16
130
  + 2
131
#endif
132
#ifdef SUPPORT_PCRE2_32
133
  + 4
134
#endif
135
0
  ;
136
0
  break;
137
138
0
  case PCRE2_CONFIG_DEPTHLIMIT:
139
0
  *((uint32_t *)where) = MATCH_LIMIT_DEPTH;
140
0
  break;
141
142
0
  case PCRE2_CONFIG_HEAPLIMIT:
143
0
  *((uint32_t *)where) = HEAP_LIMIT;
144
0
  break;
145
146
0
  case PCRE2_CONFIG_JIT:
147
#ifdef SUPPORT_JIT
148
  *((uint32_t *)where) = 1;
149
#else
150
0
  *((uint32_t *)where) = 0;
151
0
#endif
152
0
  break;
153
154
0
  case PCRE2_CONFIG_JITTARGET:
155
#ifdef SUPPORT_JIT
156
    {
157
    const char *v = PRIV(jit_get_target)();
158
    return (int)(1 + ((where == NULL)?
159
      strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
160
    }
161
#else
162
0
  return PCRE2_ERROR_BADOPTION;
163
0
#endif
164
165
0
  case PCRE2_CONFIG_LINKSIZE:
166
0
  *((uint32_t *)where) = (uint32_t)configured_link_size;
167
0
  break;
168
169
0
  case PCRE2_CONFIG_MATCHLIMIT:
170
0
  *((uint32_t *)where) = MATCH_LIMIT;
171
0
  break;
172
173
0
  case PCRE2_CONFIG_NEWLINE:
174
0
  *((uint32_t *)where) = NEWLINE_DEFAULT;
175
0
  break;
176
177
0
  case PCRE2_CONFIG_NEVER_BACKSLASH_C:
178
#ifdef NEVER_BACKSLASH_C
179
  *((uint32_t *)where) = 1;
180
#else
181
0
  *((uint32_t *)where) = 0;
182
0
#endif
183
0
  break;
184
185
0
  case PCRE2_CONFIG_PARENSLIMIT:
186
0
  *((uint32_t *)where) = PARENS_NEST_LIMIT;
187
0
  break;
188
189
  /* This is now obsolete. The stack is no longer used via recursion for
190
  handling backtracking in pcre2_match(). */
191
192
0
  case PCRE2_CONFIG_STACKRECURSE:
193
0
  *((uint32_t *)where) = 0;
194
0
  break;
195
196
0
  case PCRE2_CONFIG_TABLES_LENGTH:
197
0
  *((uint32_t *)where) = TABLES_LENGTH;
198
0
  break;
199
200
10
  case PCRE2_CONFIG_UNICODE_VERSION:
201
10
    {
202
10
#if defined SUPPORT_UNICODE
203
10
    const char *v = PRIV(unicode_version);
204
#else
205
    const char *v = "Unicode not supported";
206
#endif
207
10
    return (int)(1 + ((where == NULL)?
208
5
      strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
209
0
   }
210
0
  break;
211
212
0
  case PCRE2_CONFIG_UNICODE:
213
0
#if defined SUPPORT_UNICODE
214
0
  *((uint32_t *)where) = 1;
215
#else
216
  *((uint32_t *)where) = 0;
217
#endif
218
0
  break;
219
220
  /* The hackery in setting "v" below is to cope with the case when
221
  PCRE2_PRERELEASE is set to an empty string (which it is for real releases).
222
  If the second alternative is used in this case, it does not leave a space
223
  before the date. On the other hand, if all four macros are put into a single
224
  XSTRING when PCRE2_PRERELEASE is not empty, an unwanted space is inserted.
225
  There are problems using an "obvious" approach like this:
226
227
     XSTRING(PCRE2_MAJOR) "." XSTRING(PCRE2_MINOR)
228
     XSTRING(PCRE2_PRERELEASE) " " XSTRING(PCRE2_DATE)
229
230
  because, when PCRE2_PRERELEASE is empty, this leads to an attempted expansion
231
  of STRING(). The C standard states: "If (before argument substitution) any
232
  argument consists of no preprocessing tokens, the behavior is undefined." It
233
  turns out the gcc treats this case as a single empty string - which is what
234
  we really want - but Visual C grumbles about the lack of an argument for the
235
  macro. Unfortunately, both are within their rights. As there seems to be no
236
  way to test for a macro's value being empty at compile time, we have to
237
  resort to a runtime test. */
238
239
42
  case PCRE2_CONFIG_VERSION:
240
42
    {
241
42
    const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)?
242
42
      XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) :
243
42
      XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE);
244
42
    return (int)(1 + ((where == NULL)?
245
21
      strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
246
0
    }
247
52
  }
248
249
0
return 0;
250
52
}
251
252
/* End of pcre2_config.c */