Skip to content

Commit 22703db

Browse files
committedMay 31, 2024··
Remove old PCRE code
1 parent 5feb899 commit 22703db

File tree

4 files changed

+4
-93
lines changed

4 files changed

+4
-93
lines changed
 

‎config.h.in

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#define OSCAP_DEFAULT_CPE_PATH "@OSCAP_DEFAULT_CPE_PATH@"
3030
#define OSCAP_TEMP_DIR "@OSCAP_TEMP_DIR@"
3131

32-
#cmakedefine HAVE_PCRE2
3332

3433
#cmakedefine HAVE_ATOMIC_BUILTINS
3534

‎src/OVAL/probes/oval_fts.c

-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,6 @@ OVAL_FTS *oval_fts_open_prefixed(const char *prefix, SEXP_t *path, SEXP_t *filen
721721
ofts->ofts_path_op = path_op;
722722
if (regex != NULL) {
723723
ofts->ofts_path_regex = regex;
724-
oscap_pcre_optimize(regex);
725724
}
726725

727726
if (filesystem == OVAL_RECURSE_FS_LOCAL) {

‎src/common/oscap_pcre.c

+4-85
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,24 @@
2828

2929
#define OSCAP_PCRE_EXEC_RECURSION_LIMIT_DEFAULT 3500
3030

31-
#ifdef HAVE_PCRE2
3231
#define PCRE2_CODE_UNIT_WIDTH 8
3332
#define PCRE2_ERR_BUF_SIZE 127
3433
#include <pcre2.h>
35-
#else
36-
#include <pcre.h>
37-
#endif
34+
3835

3936
#include "debug_priv.h"
4037
#include "oscap_pcre.h"
4138

4239

4340
struct oscap_pcre {
44-
#ifdef HAVE_PCRE2
4541
pcre2_code_8 *re;
4642
pcre2_match_context_8 *re_ctx;
47-
#else
48-
pcre *re;
49-
struct pcre_extra *re_extra;
50-
#endif
5143
};
5244

5345

5446
static inline int _oscap_pcre_opts_to_pcre(oscap_pcre_options_t opts)
5547
{
5648
int res = 0;
57-
#ifdef HAVE_PCRE2
5849
if (opts & OSCAP_PCRE_OPTS_UTF8)
5950
res |= PCRE2_UTF;
6051
if (opts & OSCAP_PCRE_OPTS_MULTILINE)
@@ -67,27 +58,13 @@ static inline int _oscap_pcre_opts_to_pcre(oscap_pcre_options_t opts)
6758
res |= PCRE2_NO_UTF_CHECK;
6859
if (opts & OSCAP_PCRE_OPTS_PARTIAL)
6960
res |= PCRE2_PARTIAL_SOFT;
70-
#else
71-
if (opts & OSCAP_PCRE_OPTS_UTF8)
72-
res |= PCRE_UTF8;
73-
if (opts & OSCAP_PCRE_OPTS_MULTILINE)
74-
res |= PCRE_MULTILINE;
75-
if (opts & OSCAP_PCRE_OPTS_DOTALL)
76-
res |= PCRE_DOTALL;
77-
if (opts & OSCAP_PCRE_OPTS_CASELESS)
78-
res |= PCRE_CASELESS;
79-
if (opts & OSCAP_PCRE_OPTS_NO_UTF8_CHECK)
80-
res |= PCRE_NO_UTF8_CHECK;
81-
if (opts & OSCAP_PCRE_OPTS_PARTIAL)
82-
res |= PCRE_PARTIAL;
83-
#endif
61+
8462
return res;
8563
};
8664

8765
static inline oscap_pcre_error_t _pcre_error_to_oscap_pcre(int res)
8866
{
8967
switch (res) {
90-
#ifdef HAVE_PCRE2
9168
case PCRE2_ERROR_NOMATCH:
9269
return OSCAP_PCRE_ERR_NOMATCH;
9370
case PCRE2_ERROR_PARTIAL:
@@ -116,18 +93,6 @@ static inline oscap_pcre_error_t _pcre_error_to_oscap_pcre(int res)
11693
return OSCAP_PCRE_ERR_BADUTF8;
11794
case PCRE2_ERROR_RECURSIONLIMIT:
11895
return OSCAP_PCRE_ERR_RECURSIONLIMIT;
119-
#else
120-
case PCRE_ERROR_NOMATCH:
121-
return OSCAP_PCRE_ERR_NOMATCH;
122-
case PCRE_ERROR_PARTIAL:
123-
return OSCAP_PCRE_ERR_PARTIAL;
124-
case PCRE_ERROR_BADPARTIAL:
125-
return OSCAP_PCRE_ERR_BADPARTIAL;
126-
case PCRE_ERROR_BADUTF8:
127-
return OSCAP_PCRE_ERR_BADUTF8;
128-
case PCRE_ERROR_RECURSIONLIMIT:
129-
return OSCAP_PCRE_ERR_RECURSIONLIMIT;
130-
#endif
13196
default:
13297
dW("Unknown PCRE error code: %d", res);
13398
return OSCAP_PCRE_ERR_UNKNOWN;
@@ -138,7 +103,6 @@ oscap_pcre_t *oscap_pcre_compile(const char *pattern, oscap_pcre_options_t optio
138103
char **errptr, int *erroffset)
139104
{
140105
oscap_pcre_t *res = malloc(sizeof(oscap_pcre_t));
141-
#ifdef HAVE_PCRE2
142106
int errno;
143107
PCRE2_SIZE erroffset2;
144108
res->re_ctx = NULL;
@@ -151,58 +115,27 @@ oscap_pcre_t *oscap_pcre_compile(const char *pattern, oscap_pcre_options_t optio
151115
*erroffset = erroffset2;
152116
*errptr = strdup((const char*)errmsg);
153117
}
154-
#else
155-
res->re_extra = NULL;
156-
dD("pcre_compile: patt=%s", pattern);
157-
res->re = pcre_compile(pattern, _oscap_pcre_opts_to_pcre(options), (const char **)errptr, erroffset, NULL);
158-
if (res->re == NULL)
159-
dW("pcre_compile: error (at offset %d): %s", *erroffset, *errptr);
160-
#endif
118+
161119
if (res->re == NULL) {
162120
free(res);
163121
res = NULL;
164122
}
165123
return res;
166124
}
167125

168-
void oscap_pcre_optimize(oscap_pcre_t *opcre)
169-
{
170-
#ifdef HAVE_PCRE2
171-
// This is a NOOP for PCRE2 as all patterns are optimized
172-
// unless the library configured differently.
173-
#else
174-
const char *errptr = NULL;
175-
pcre_extra *extra = pcre_study(opcre->re, 0, &errptr);
176-
if (extra != NULL) {
177-
if (opcre->re_extra != NULL)
178-
free(opcre->re_extra);
179-
opcre->re_extra = extra;
180-
}
181-
#endif
182-
}
183-
184126
void oscap_pcre_set_match_limit_recursion(oscap_pcre_t *opcre, unsigned long limit)
185127
{
186-
#ifdef HAVE_PCRE2
187128
if (opcre->re_ctx == NULL) {
188129
opcre->re_ctx = pcre2_match_context_create_8(NULL);
189130
}
190131
pcre2_set_depth_limit_8(opcre->re_ctx, limit);
191-
#else
192-
if (opcre->re_extra == NULL) {
193-
opcre->re_extra = calloc(1, sizeof(struct pcre_extra));
194-
}
195-
opcre->re_extra->match_limit_recursion = limit;
196-
opcre->re_extra->flags = PCRE_EXTRA_MATCH_LIMIT_RECURSION;
197-
#endif
198132
}
199133

200134
int oscap_pcre_exec(const oscap_pcre_t *opcre, const char *subject,
201135
int length, int startoffset, oscap_pcre_options_t options,
202136
int *ovector, int ovecsize)
203137
{
204138
int rc = 0;
205-
#ifdef HAVE_PCRE2
206139
// The ovecsize is multiplied by 3 in the code for compatibility with PCRE1
207140
int ovecsize2 = ovecsize/3;
208141
pcre2_match_data_8 *mdata = pcre2_match_data_create_8(ovecsize2, NULL);
@@ -221,26 +154,16 @@ int oscap_pcre_exec(const oscap_pcre_t *opcre, const char *subject,
221154
}
222155
}
223156
pcre2_match_data_free_8(mdata);
224-
#else
225-
dD("pcre_exec: subj=%s", subject);
226-
rc = pcre_exec(opcre->re, opcre->re_extra, subject, length, startoffset, _oscap_pcre_opts_to_pcre(options), ovector, ovecsize);
227-
dD("pcre_exec: rc=%d, ", rc);
228-
#endif
157+
229158
return rc >= 0 ? rc : _pcre_error_to_oscap_pcre(rc);
230159
}
231160

232161
void oscap_pcre_free(oscap_pcre_t *opcre)
233162
{
234163
if (opcre != NULL) {
235-
#ifdef HAVE_PCRE2
236164
if (opcre->re_ctx != NULL)
237165
pcre2_match_context_free_8(opcre->re_ctx);
238166
pcre2_code_free_8(opcre->re);
239-
#else
240-
if (opcre->re_extra != NULL)
241-
free(opcre->re_extra);
242-
pcre_free(opcre->re);
243-
#endif
244167
free(opcre);
245168
}
246169
}
@@ -318,11 +241,7 @@ int oscap_pcre_get_substrings(char *str, int *ofs, oscap_pcre_t *re, int want_su
318241
void oscap_pcre_err_free(char *err)
319242
{
320243
if (err != NULL) {
321-
#ifdef HAVE_PCRE2
322244
free(err);
323-
#else
324-
// PCRE1 error messages are static, NOOP.
325-
#endif
326245
}
327246
}
328247

‎src/common/oscap_pcre.h

-6
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ void oscap_pcre_free(oscap_pcre_t *opcre);
9090
*/
9191
void oscap_pcre_set_match_limit_recursion(oscap_pcre_t *opcre, unsigned long limit);
9292

93-
/**
94-
* Optimize the compiled regular expression object to increase matching speed.
95-
* @param opcre the oscap_pcre_t object
96-
*/
97-
void oscap_pcre_optimize(oscap_pcre_t *opcre);
98-
9993
/**
10094
* Match a regular expression and return substrings.
10195
* Caller is responsible for freeing the returned array.

0 commit comments

Comments
 (0)
Please sign in to comment.