Skip to content

Commit c5a6d6b

Browse files
author
Marc Stern
committed
Revert to OWASP
2 parents e406bca + 705002b commit c5a6d6b

File tree

11 files changed

+916
-864
lines changed

11 files changed

+916
-864
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Quality Assurance
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build-linux:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os: [ubuntu-22.04]
13+
platform: [x64]
14+
compiler: [gcc]
15+
configure:
16+
- {label: "with pcre2", opt: "--with-pcre2" }
17+
- {label: "with lua", opt: "--with-lua" }
18+
- {label: "wo lua", opt: "--without-lua" }
19+
steps:
20+
- name: Setup Dependencies
21+
run: |
22+
sudo apt-get update -y -qq
23+
sudo apt-get install -y apache2-dev libxml2-dev liblua5.1-0-dev libcurl4-gnutls-dev libpcre2-dev pkg-config libyajl-dev
24+
- uses: actions/checkout@v2
25+
- name: autogen.sh
26+
run: ./autogen.sh
27+
- name: configure ${{ matrix.configure.label }}
28+
run: ./configure ${{ matrix.configure.opt }}
29+
- uses: ammaraskar/gcc-problem-matcher@master
30+
- name: make
31+
run: make -j `nproc`

apache2/msc_json.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,15 @@ int json_init(modsec_rec *msr, char **error_msg) {
354354
int json_process_chunk(modsec_rec *msr, const char *buf, unsigned int size, char **error_msg) {
355355
if (error_msg == NULL) return -1;
356356
*error_msg = NULL;
357-
// Take a copy in case libyajl decodes the buffer inline
358-
base_offset = apr_pstrmemdup(msr->mp, buf, size);
359-
if (!base_offset) return -1;
357+
base_offset=buf;
360358

361359
/* Feed our parser and catch any errors */
362-
msr->json->status = yajl_parse(msr->json->handle, (unsigned char*)base_offset, size);
360+
msr->json->status = yajl_parse(msr->json->handle, buf, size);
363361
if (msr->json->status != yajl_status_ok) {
364362
if (msr->json->depth_limit_exceeded) {
365363
*error_msg = "JSON depth limit exceeded";
366364
} else {
367-
char *yajl_err = yajl_get_error(msr->json->handle, 0, base_offset, size);
365+
char *yajl_err = yajl_get_error(msr->json->handle, 0, buf, size);
368366
*error_msg = apr_pstrdup(msr->mp, yajl_err);
369367
yajl_free_error(msr->json->handle, yajl_err);
370368
}

apache2/msc_logging.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,15 @@ static char *construct_auditlog_filename(apr_pool_t *mp, const char *uniqueid) {
234234
* This is required for mpm-itk & mod_ruid2, though should be harmless for other implementations
235235
* It also changes the return statement.
236236
*/
237-
char *userinfo = get_username(mp);
237+
char *userinfo;
238+
apr_status_t rc;
239+
apr_uid_t uid;
240+
apr_gid_t gid;
241+
apr_uid_current(&uid, &gid, mp);
242+
rc = apr_uid_name_get(&userinfo, uid, mp);
243+
if (rc != APR_SUCCESS) {
244+
userinfo = apr_psprintf(mp, "%u", uid);
245+
}
238246

239247
apr_time_exp_lt(&t, apr_time_now());
240248

apache2/msc_pcre.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ static apr_status_t msc_pcre_cleanup(msc_regex_t *regex) {
3131
}
3232
#else
3333
if (regex->pe != NULL) {
34+
#if defined(VERSION_NGINX)
3435
pcre_free(regex->pe);
36+
#else
37+
free(regex->pe);
38+
#endif
3539
regex->pe = NULL;
3640
}
3741
if (regex->re != NULL) {
@@ -148,15 +152,19 @@ void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options,
148152

149153
#ifdef WITH_PCRE_STUDY
150154
#ifdef WITH_PCRE_JIT
151-
pe = pcre_study(regex->re, PCRE_STUDY_EXTRA_NEEDED|PCRE_STUDY_JIT_COMPILE, &errptr);
155+
pe = pcre_study(regex->re, PCRE_STUDY_JIT_COMPILE, &errptr);
152156
#else
153-
pe = pcre_study(regex->re, PCRE_STUDY_EXTRA_NEEDED, &errptr);
157+
pe = pcre_study(regex->re, 0, &errptr);
154158
#endif
155159
#endif
156160

157161
/* Setup the pcre_extra record if pcre_study did not already do it */
158162
if (pe == NULL) {
159-
pe = (pcre_extra*)pcre_malloc(sizeof(pcre_extra));
163+
#if defined(VERSION_NGINX)
164+
pe = pcre_malloc(sizeof(pcre_extra));
165+
#else
166+
pe = malloc(sizeof(pcre_extra));
167+
#endif
160168
if (pe == NULL) {
161169
return NULL;
162170
}

apache2/msc_util.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,14 +2843,3 @@ char* strtok_r(
28432843
}
28442844
#endif
28452845

2846-
// Function compatible with Linux & Windows, also with mpm-itk & mod_ruid2
2847-
char* get_username(apr_pool_t* mp) {
2848-
char* username;
2849-
apr_uid_t uid;
2850-
apr_gid_t gid;
2851-
int rc = apr_uid_current(&uid, &gid, mp);
2852-
if (rc != APR_SUCCESS) return "apache";
2853-
rc = apr_uid_name_get(&username, uid, mp);
2854-
if (rc != APR_SUCCESS) return "apache";
2855-
return username;
2856-
}

apache2/msc_util.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ int DSOLOCAL tree_contains_ip(apr_pool_t *mp, TreeRoot *rtree,
159159
int DSOLOCAL ip_tree_from_param(apr_pool_t *pool,
160160
char *param, TreeRoot **rtree, char **error_msg);
161161

162-
char DSOLOCAL *get_username(apr_pool_t* mp);
163-
164162
#ifdef WITH_CURL
165163
int ip_tree_from_uri(TreeRoot **rtree, char *uri,
166164
apr_pool_t *mp, char **error_msg);

0 commit comments

Comments
 (0)