Fix screwup, fixes #137

1.修复HTTP2压缩段错误
2.修改发送无效的9字节DATA帧
3.对manipulate_profile结构多线程调用加锁处理
This commit is contained in:
fengweihao
2019-06-08 10:57:49 +08:00
parent 0eea8bd2a2
commit 814d5b4a30
3 changed files with 36 additions and 15 deletions

View File

@@ -98,6 +98,7 @@ struct manipulate_profile
char *profile_msg;
char *profile_type;
ctemplate::Template * tpl;
pthread_mutex_t lock;
};
struct policy_action_param
@@ -639,6 +640,8 @@ void ma_profile_table_new_cb(int table_id, const char* key, const char* table_li
ply_profile->profile_id=profile_id;
ply_profile->ref_cnt=1;
pthread_mutex_init(&(ply_profile->lock), NULL);
if(strcasecmp(formate, "template") == 0)
{
ply_profile->tpl = ctemplate::Template::GetTemplate(profile_path, ctemplate::DO_NOT_STRIP);
@@ -673,6 +676,7 @@ void ma_hijack_profile_table_new_cb(int table_id, const char* key, const char* t
}
struct manipulate_profile* ply_profile=ALLOC(struct manipulate_profile, 1);
ply_profile->ref_cnt=1;
pthread_mutex_init(&(ply_profile->lock), NULL);
ply_profile->profile_id=profile_id;
ply_profile->profile_msg=tfe_strdup(profile_path);
@@ -687,17 +691,27 @@ void ma_hijack_profile_table_new_cb(int table_id, const char* key, const char* t
void ma_profile_table_free_cb(int table_id, MAAT_PLUGIN_EX_DATA* ad, long argl, void *argp)
{
struct manipulate_profile* ply_obj=(struct manipulate_profile*)(*ad);
ply_obj->ref_cnt--;
if (ply_obj->ref_cnt==0)
if(*ad==NULL)
{
return;
}
struct manipulate_profile* ply_obj=(struct manipulate_profile*)(*ad);
pthread_mutex_lock(&(ply_obj->lock));
ply_obj->ref_cnt--;
if(ply_obj->ref_cnt>0)
{
pthread_mutex_unlock(&(ply_obj->lock));
return;
}
pthread_mutex_unlock(&(ply_obj->lock));
pthread_mutex_destroy(&(ply_obj->lock));
FREE(&ply_obj->profile_type);
FREE(&ply_obj->profile_msg);
FREE(&ply_obj->profile_name);
FREE(&ply_obj);
*ad=NULL;
}
return;
}
void ma_profile_table_free(struct manipulate_profile* ply_obj)
@@ -708,7 +722,9 @@ void ma_profile_table_free(struct manipulate_profile* ply_obj)
void ma_profile_table_dup_cb(int table_id, MAAT_PLUGIN_EX_DATA *to, MAAT_PLUGIN_EX_DATA *from, long argl, void *argp)
{
struct manipulate_profile* ply_obj=(struct manipulate_profile*)(*from);
pthread_mutex_lock(&(ply_obj->lock));
ply_obj->ref_cnt++;
pthread_mutex_unlock(&(ply_obj->lock));
*to=ply_obj;
}
@@ -1566,7 +1582,7 @@ static void http_hijack(const struct tfe_http_session * session, enum tfe_http_e
struct manipulate_profile* hijack_profile=get_profile_by_id(POLICY_PROFILE_TABLE_HIJACK, param->profile_id);
if (NULL == hijack_profile)
{
TFE_LOG_ERROR(g_pangu_rt->local_logger, "get table obj faild, table_id = %d", param->profile_id);
TFE_LOG_ERROR(g_pangu_rt->local_logger, "get table obj faild, profile_id = %d", param->profile_id);
ctx->action = PG_ACTION_NONE;
return;
}

View File

@@ -189,7 +189,7 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
char src_ip_str[MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)] = {0};
char dst_ip_str[MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)] = {0};
const char *app_proto[]= {"unkonw","http1.0", "http2.0"};
const char *app_proto[]= {"unkonw","http1", "http2"};
struct json_spec req_fields[]={ {"cookie", TFE_HTTP_COOKIE},
{"referer", TFE_HTTP_REFERER},

View File

@@ -387,7 +387,7 @@ h2_half_ops_append_body(struct tfe_http_half * half, char * buff, size_t size, i
struct tfe_h2_half_private * resp = nghttp2_to_half_private(half);
struct tfe_h2_payload *body = &resp->h2_payload;
if (buff == NULL && size == 0){
if (buff == NULL || size == 0){
if (body->gzip != HTTP2_CONTENT_ENCODING_NONE){
xret = deflate_write(&body->deflate, NULL, 0, resp->h2_payload.evbuf_body, body->gzip, 1);
}
@@ -661,6 +661,10 @@ upstream_read_callback(nghttp2_session *session, int32_t stream_id,
if (!to_send_body->evbuf_body || !(input = evbuffer_pullup(to_send_body->evbuf_body, -1))
|| 0==(inputlen = evbuffer_get_length(to_send_body->evbuf_body)))
{
if ((to_send_body->flags & NGHTTP2_FLAG_END_STREAM) == 0)
{
*data_flags |= NGHTTP2_DATA_FLAG_NO_END_STREAM;
}
*data_flags |= NGHTTP2_DATA_FLAG_EOF;
return 0;
}
@@ -689,6 +693,7 @@ nghttp2_server_frame_submit_response(struct tfe_h2_stream *h2_stream_info,
return ACTION_FORWARD_DATA;
struct tfe_h2_payload *body = &pangu_resp->h2_payload;
body->flags |= NGHTTP2_FLAG_END_STREAM;
char str_sz_evbuf_body[TFE_STRING_MAX];
snprintf(str_sz_evbuf_body, sizeof(str_sz_evbuf_body) - 1, "%lu", evbuffer_get_length(body->evbuf_body));