summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfengweihao <[email protected]>2019-06-29 19:39:29 +0800
committerfengweihao <[email protected]>2019-06-29 19:39:29 +0800
commit348afbc00d76c5ebc877c5067b30903fadd9ee3d (patch)
tree07e13ce65eb225984efa3110e690bddfc2c8170b
parent455c8c1a93a14d9a3ec0e73e0d77ad5a2e1ede96 (diff)
1.修复替换字符编码大小写匹配错误,造成页面替换失败v4.0.5-20190630
2.修复命中insert后,发送无效日志 3.修复正则表达式失败返回-1,size_t造成数据反转
-rw-r--r--plugin/business/pangu-http/src/pangu_http.cpp42
-rw-r--r--plugin/business/pangu-http/src/pattern_replace.cpp2
2 files changed, 38 insertions, 6 deletions
diff --git a/plugin/business/pangu-http/src/pangu_http.cpp b/plugin/business/pangu-http/src/pangu_http.cpp
index e71e962..b77f37e 100644
--- a/plugin/business/pangu-http/src/pangu_http.cpp
+++ b/plugin/business/pangu-http/src/pangu_http.cpp
@@ -1412,7 +1412,8 @@ void http_replace(const struct tfe_stream * stream, const struct tfe_http_sessio
rewrite_sz = 0;
if (tfe_http_in_response(events) && in_resp_spec->content_type != NULL
- && strstr(in_resp_spec->content_type, "charset=utf-8"))
+ && (strstr(in_resp_spec->content_type, "charset=utf-8") ||
+ (strstr(in_resp_spec->content_type, "charset=UTF-8"))))
{
options = 1;
}
@@ -2313,6 +2314,36 @@ void pangu_on_http_begin(const struct tfe_stream * stream,
return;
}
+static inline int ctx_actually_replaced(struct pangu_http_ctx * ctx)
+{
+
+ if(ctx->action == PG_ACTION_MANIPULATE &&
+ ctx->param->action == MA_ACTION_REPLACE &&
+ ctx->n_enforce==1 && ctx->rep_ctx->actually_replaced==0)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+static inline int ctx_actually_inserted(struct pangu_http_ctx * ctx)
+{
+
+ if(ctx->action == PG_ACTION_MANIPULATE &&
+ ctx->param->action == MA_ACTION_INSERT &&
+ ctx->n_enforce==1 && ctx->ins_ctx->actually_replaced==0)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
void pangu_on_http_end(const struct tfe_stream * stream,
const struct tfe_http_session * session, unsigned int thread_id, void ** pme)
{
@@ -2342,10 +2373,11 @@ void pangu_on_http_end(const struct tfe_stream * stream,
}
struct pangu_log log_msg = {.stream=stream, .http=session, .result=ctx->enforce_rules, .result_num=ctx->n_enforce,
.req_body= ctx->log_req_body, .resp_body=ctx->log_resp_body};
- if (ctx->action != PG_ACTION_NONE&&
- !(ctx->action == PG_ACTION_MANIPULATE &&
- ctx->param->action == MA_ACTION_REPLACE &&
- ctx->n_enforce==1 && ctx->rep_ctx->actually_replaced==0))
+
+ if ((ctx->action != PG_ACTION_NONE&&
+ !(ctx_actually_replaced(ctx))) ||
+ (ctx->action != PG_ACTION_NONE&&
+ !(ctx_actually_inserted(ctx))))
{
ret=pangu_send_log(g_pangu_rt->send_logger, &log_msg);
ATOMIC_ADD(&(g_pangu_rt->stat_val[STAT_LOG_NUM]), ret);
diff --git a/plugin/business/pangu-http/src/pattern_replace.cpp b/plugin/business/pangu-http/src/pattern_replace.cpp
index ea910c5..9e54bae 100644
--- a/plugin/business/pangu-http/src/pattern_replace.cpp
+++ b/plugin/business/pangu-http/src/pattern_replace.cpp
@@ -202,7 +202,7 @@ size_t replace_string(const char * in, size_t in_sz, const struct replace_rule *
pcre2_code *re = pcre2_compile(pattern, strlen(zone->find), pcre2_options, &error, &erroffset, 0);
if (!re)
- return -1;
+ return 0;
pcre2_jit_compile(re, PCRE2_JIT_COMPLETE);