Skip to content
Snippets Groups Projects
Commit 24e4ecf0 authored by Janis Danisevskis's avatar Janis Danisevskis Committed by android-build-merger
Browse files

Port from pcre to pcre2 (Fix wrong merge decision) am: 750d797b

am: aaa363cd

Change-Id: Ieb71a3d8c51fd33ee60213fad43824db18da59aa
parents 4fb4965f aaa363cd
No related branches found
No related tags found
No related merge requests found
...@@ -5,12 +5,11 @@ include $(CLEAR_VARS) ...@@ -5,12 +5,11 @@ include $(CLEAR_VARS)
LOCAL_MODULE := checkseapp LOCAL_MODULE := checkseapp
LOCAL_MODULE_TAGS := optional LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := \ LOCAL_C_INCLUDES := \
external/pcre \
external/selinux/libsepol/include external/selinux/libsepol/include
LOCAL_CFLAGS := -DLINK_SEPOL_STATIC -Wall -Werror LOCAL_CFLAGS := -DLINK_SEPOL_STATIC -Wall -Werror
LOCAL_SRC_FILES := check_seapp.c LOCAL_SRC_FILES := check_seapp.c
LOCAL_STATIC_LIBRARIES := libsepol LOCAL_STATIC_LIBRARIES := libsepol
LOCAL_WHOLE_STATIC_LIBRARIES := libpcre LOCAL_WHOLE_STATIC_LIBRARIES := libpcre2
LOCAL_CXX_STL := none LOCAL_CXX_STL := none
include $(BUILD_HOST_EXECUTABLE) include $(BUILD_HOST_EXECUTABLE)
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <sepol/sepol.h> #include <sepol/sepol.h>
#include <sepol/policydb/policydb.h> #include <sepol/policydb/policydb.h>
#include <pcre.h> #include <pcre2.h>
#define TABLE_SIZE 1024 #define TABLE_SIZE 1024
#define KVP_NUM_OF_RULES (sizeof(rules) / sizeof(key_map)) #define KVP_NUM_OF_RULES (sizeof(rules) / sizeof(key_map))
...@@ -91,8 +91,8 @@ struct list { ...@@ -91,8 +91,8 @@ struct list {
}; };
struct key_map_regex { struct key_map_regex {
pcre *compiled; pcre2_code *compiled;
pcre_extra *extra; pcre2_match_data *match_data;
}; };
/** /**
...@@ -320,14 +320,15 @@ static bool match_regex(key_map *assert, const key_map *check) { ...@@ -320,14 +320,15 @@ static bool match_regex(key_map *assert, const key_map *check) {
char *tomatch = check->data; char *tomatch = check->data;
int ret = pcre_exec(assert->regex.compiled, assert->regex.extra, tomatch, int ret = pcre2_match(assert->regex.compiled, (PCRE2_SPTR) tomatch,
strlen(tomatch), 0, 0, NULL, 0); PCRE2_ZERO_TERMINATED, 0, 0,
assert->regex.match_data, NULL);
/* 0 from pcre_exec means matched */ /* ret > 0 from pcre2_match means matched */
return !ret; return ret > 0;
} }
static bool compile_regex(key_map *km, const char **errbuf, int *erroff) { static bool compile_regex(key_map *km, int *errcode, PCRE2_SIZE *erroff) {
size_t size; size_t size;
char *anchored; char *anchored;
...@@ -341,13 +342,21 @@ static bool compile_regex(key_map *km, const char **errbuf, int *erroff) { ...@@ -341,13 +342,21 @@ static bool compile_regex(key_map *km, const char **errbuf, int *erroff) {
anchored = alloca(size); anchored = alloca(size);
sprintf(anchored, "^%s$", km->data); sprintf(anchored, "^%s$", km->data);
km->regex.compiled = pcre_compile(anchored, PCRE_DOTALL, errbuf, erroff, km->regex.compiled = pcre2_compile((PCRE2_SPTR) anchored,
NULL ); PCRE2_ZERO_TERMINATED,
PCRE2_DOTALL,
errcode, erroff,
NULL);
if (!km->regex.compiled) { if (!km->regex.compiled) {
return false; return false;
} }
km->regex.extra = pcre_study(km->regex.compiled, 0, errbuf); km->regex.match_data = pcre2_match_data_create_from_pattern(
km->regex.compiled, NULL);
if (!km->regex.match_data) {
pcre2_code_free(km->regex.compiled);
return false;
}
return true; return true;
} }
...@@ -423,12 +432,13 @@ static bool validate_selinux_level(char *value, char **errmsg) { ...@@ -423,12 +432,13 @@ static bool validate_selinux_level(char *value, char **errmsg) {
static bool key_map_validate(key_map *m, const char *filename, int lineno, static bool key_map_validate(key_map *m, const char *filename, int lineno,
bool is_neverallow) { bool is_neverallow) {
int erroff; PCRE2_SIZE erroff;
const char *errbuf; int errcode;
bool rc = true; bool rc = true;
char *key = m->name; char *key = m->name;
char *value = m->data; char *value = m->data;
char *errmsg = NULL; char *errmsg = NULL;
char errstr[256];
log_info("Validating %s=%s\n", key, value); log_info("Validating %s=%s\n", key, value);
...@@ -438,10 +448,13 @@ static bool key_map_validate(key_map *m, const char *filename, int lineno, ...@@ -438,10 +448,13 @@ static bool key_map_validate(key_map *m, const char *filename, int lineno,
*/ */
if (is_neverallow) { if (is_neverallow) {
if (!m->regex.compiled) { if (!m->regex.compiled) {
rc = compile_regex(m, &errbuf, &erroff); rc = compile_regex(m, &errcode, &erroff);
if (!rc) { if (!rc) {
log_error("Invalid regex on line %d : %s PCRE error: %s at offset %d", pcre2_get_error_message(errcode,
lineno, value, errbuf, erroff); (PCRE2_UCHAR*) errstr,
sizeof(errstr));
log_error("Invalid regex on line %d : %s PCRE error: %s at offset %lu",
lineno, value, errstr, erroff);
} }
} }
goto out; goto out;
...@@ -572,11 +585,11 @@ static void rule_map_free(rule_map *rm, bool is_in_htable) { ...@@ -572,11 +585,11 @@ static void rule_map_free(rule_map *rm, bool is_in_htable) {
free(m->data); free(m->data);
if (m->regex.compiled) { if (m->regex.compiled) {
pcre_free(m->regex.compiled); pcre2_code_free(m->regex.compiled);
} }
if (m->regex.extra) { if (m->regex.match_data) {
pcre_free_study(m->regex.extra); pcre2_match_data_free(m->regex.match_data);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment