修复规则命中应答头后,redirect、block无效

修复由于加载inset文件失败,后续处理可能存在问题
This commit is contained in:
fengweihao
2019-06-15 18:19:15 +08:00
parent 0db61c2a66
commit 048c60439d
2 changed files with 12 additions and 3 deletions

View File

@@ -1006,7 +1006,8 @@ void http_repl_ctx_free(struct replace_ctx* rep_ctx)
void http_ins_ctx_free(struct insert_ctx* ins_ctx) void http_ins_ctx_free(struct insert_ctx* ins_ctx)
{ {
FREE(&ins_ctx->rule->script); if (ins_ctx->rule->script)
FREE(&ins_ctx->rule->script);
FREE(&ins_ctx->rule->type); FREE(&ins_ctx->rule->type);
if (ins_ctx->rule->position) if (ins_ctx->rule->position)
FREE(&ins_ctx->rule->position); FREE(&ins_ctx->rule->position);
@@ -1404,7 +1405,8 @@ void http_replace(const struct tfe_stream * stream, const struct tfe_http_sessio
rewrite_buff = NULL; rewrite_buff = NULL;
rewrite_sz = 0; rewrite_sz = 0;
if (in_resp_spec->content_type != NULL && strstr(in_resp_spec->content_type, "charset=utf-8")) if (in_resp_spec != NULL && in_resp_spec->content_type != NULL
&& strstr(in_resp_spec->content_type, "charset=utf-8"))
{ {
options = 1; options = 1;
} }
@@ -1831,6 +1833,7 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht
void * iterator = NULL; void * iterator = NULL;
const char * field_val = NULL; const char * field_val = NULL;
struct http_field_name field_name; struct http_field_name field_name;
struct tfe_http_half * http_half;
struct Maat_rule_t result[MAX_SCAN_RESULT]; struct Maat_rule_t result[MAX_SCAN_RESULT];
char buff[TFE_STRING_MAX], * p = NULL; char buff[TFE_STRING_MAX], * p = NULL;
int scan_ret = 0, table_id = 0; int scan_ret = 0, table_id = 0;
@@ -1854,9 +1857,10 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht
{ {
table_id = events & EV_HTTP_REQ_HDR ? g_pangu_rt->scan_table_id[PXY_CTRL_HTTP_REQ_HDR] : g_pangu_rt table_id = events & EV_HTTP_REQ_HDR ? g_pangu_rt->scan_table_id[PXY_CTRL_HTTP_REQ_HDR] : g_pangu_rt
->scan_table_id[PXY_CTRL_HTTP_RES_HDR]; ->scan_table_id[PXY_CTRL_HTTP_RES_HDR];
http_half = events & EV_HTTP_REQ_HDR ? session->req : session->resp;
while (hit_cnt < MAX_SCAN_RESULT) while (hit_cnt < MAX_SCAN_RESULT)
{ {
field_val = tfe_http_field_iterate(session->req, &iterator, &field_name); field_val = tfe_http_field_iterate(http_half, &iterator, &field_name);
if (field_val == NULL) if (field_val == NULL)
{ {
break; break;

View File

@@ -321,6 +321,11 @@ size_t insert_string(char * in, size_t in_sz, const char *insert_on, const char
char* insert_from=NULL; char* insert_from=NULL;
size_t offset=0; size_t offset=0;
if (script == NULL)
{
return 0;
}
if (insert_on != NULL && 0==strcasecmp(insert_on, "after-page-load")) if (insert_on != NULL && 0==strcasecmp(insert_on, "after-page-load"))
{ {
insert_from=strstr(in, "</body>"); insert_from=strstr(in, "</body>");