Fix illegal reading and writing.
This commit is contained in:
parent
3c8a3747ef
commit
4b40444806
@ -8,16 +8,16 @@ global {
|
||||
}
|
||||
|
||||
http {
|
||||
http_ip=8.210.203.112;
|
||||
http_ip=47.240.75.93;
|
||||
http_port=124;
|
||||
http_del="x-online-host,X-Online-Host,host,Host";
|
||||
http_first="[M] http://[host][U] [V]\r\nHost: [host]\r\n";
|
||||
//strrep="Windows NT 10.0->Linux";
|
||||
//regrep="User-Agent:*.+?->User-Agent: aixiao.me";
|
||||
//regrep="Host:*.+?->Host: [host]:80";
|
||||
}
|
||||
|
||||
https {
|
||||
https_ip=8.210.203.112;
|
||||
https_ip=47.240.75.93;
|
||||
https_port=124;
|
||||
https_del="Host,host,x-online-host";
|
||||
https_first="[M] [U] [V]\r\nHost: [host]\r\n";
|
||||
|
@ -276,16 +276,16 @@ void parse_request_head(char *http_request_line, struct http_request *http_reque
|
||||
if (http_request->U_len < 0)
|
||||
return;
|
||||
|
||||
http_request->host = (char *)malloc(sizeof(char) * head_len);
|
||||
http_request->host = (char *)malloc(sizeof(char) * head_len + CACHE_SIZE);
|
||||
http_request->port = (char *)malloc(sizeof(char) * head_len);
|
||||
http_request->url = (char *)malloc(sizeof(char) * head_len);
|
||||
http_request->uri = (char *)malloc(sizeof(char) * head_len);
|
||||
http_request->H = (char *)malloc(sizeof(char) * head_len * 2);
|
||||
memset(http_request->host, '\0', head_len);
|
||||
memset(http_request->port, '\0', head_len);
|
||||
memset(http_request->url, '\0', head_len);
|
||||
memset(http_request->uri, '\0', head_len);
|
||||
memset(http_request->H, '\0', head_len * 2);
|
||||
memset(http_request->host, 0, head_len + CACHE_SIZE);
|
||||
memset(http_request->port, 0, head_len);
|
||||
memset(http_request->url, 0, head_len);
|
||||
memset(http_request->uri, 0, head_len);
|
||||
memset(http_request->H, 0, head_len * 2);
|
||||
|
||||
if (extract_host(http_request_line, http_request->host, http_request->port) == -1)
|
||||
return;
|
||||
@ -309,6 +309,8 @@ char *request_head(conn * in, conf * configure)
|
||||
{
|
||||
struct http_request *http_request;
|
||||
http_request = (struct http_request *)malloc(sizeof(struct http_request));
|
||||
memset(http_request, 0, sizeof(struct http_request));
|
||||
|
||||
parse_request_head(in->header_buffer, http_request);
|
||||
|
||||
if (strncmp(in->header_buffer, "CONNECT", 7) == 0) {
|
||||
@ -391,10 +393,6 @@ char *request_head(conn * in, conf * configure)
|
||||
}
|
||||
splice_head(incomplete_head, "\n", configure->http_first);
|
||||
incomplete_head_len = strlen(incomplete_head);
|
||||
if (configure->http_strrep)
|
||||
incomplete_head = replace(incomplete_head, &incomplete_head_len, configure->http_strrep_aim, configure->http_strrep_aim_len, configure->http_strrep_obj, configure->http_strrep_obj_len);
|
||||
if (configure->http_regrep)
|
||||
incomplete_head = regrep(incomplete_head, &incomplete_head_len, configure->http_regrep_aim, configure->http_regrep_obj, configure->http_regrep_obj_len);
|
||||
incomplete_head = replace(incomplete_head, &incomplete_head_len, "\\r", 2, "\r", 1);
|
||||
incomplete_head = replace(incomplete_head, &incomplete_head_len, "\\n", 2, "\n", 1);
|
||||
incomplete_head = replace(incomplete_head, &incomplete_head_len, "\\b", 2, "\b", 1);
|
||||
@ -414,11 +412,16 @@ char *request_head(conn * in, conf * configure)
|
||||
incomplete_head = replace(incomplete_head, &incomplete_head_len, "[host]", 6, http_request->host, http_request->host_len);
|
||||
incomplete_head = replace(incomplete_head, &incomplete_head_len, "[port]", 6, http_request->port, http_request->port_len);
|
||||
incomplete_head = replace(incomplete_head, &incomplete_head_len, "[H]", 3, http_request->H, http_request->H_len);
|
||||
//printf("%s", incomplete_head);
|
||||
if (configure->http_strrep)
|
||||
incomplete_head = replace(incomplete_head, &incomplete_head_len, configure->http_strrep_aim, configure->http_strrep_aim_len, configure->http_strrep_obj, configure->http_strrep_obj_len);
|
||||
if (configure->http_regrep)
|
||||
incomplete_head = regrep(incomplete_head, &incomplete_head_len, configure->http_regrep_aim, configure->http_regrep_obj, configure->http_regrep_obj_len);
|
||||
incomplete_head = replace(incomplete_head, &incomplete_head_len, "[host]", 6, http_request->host, http_request->host_len);
|
||||
incomplete_head_len = strlen(incomplete_head);
|
||||
//printf("%s", incomplete_head);
|
||||
|
||||
memset(in->header_buffer, 0, strlen(in->header_buffer));
|
||||
memmove(in->header_buffer, incomplete_head, incomplete_head_len);
|
||||
memset(in->header_buffer, 0, in->header_buffer_len);
|
||||
memmove(in->header_buffer, incomplete_head, incomplete_head_len + 1);
|
||||
in->header_buffer_len = strlen(in->header_buffer);
|
||||
free(incomplete_head);
|
||||
}
|
||||
|
31
main.c
31
main.c
@ -181,9 +181,9 @@ int process_signal(int signal, char *process_name)
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
if (signal == SERVER_STATUS) { // 状态
|
||||
n -= 2; // 去除最后一个搜索时的本身进程和最后加一后未使用的
|
||||
for (; n >= 0; n--) { // 依据数组从大到小的下标打印PID
|
||||
if (signal == SERVER_STATUS) { // 状态
|
||||
n -= 2; // 去除最后一个搜索时的本身进程和最后加一后未使用的
|
||||
for (; n >= 0; n--) { // 依据数组从大到小的下标打印PID
|
||||
printf("\t%d\n", number[n]);
|
||||
}
|
||||
}
|
||||
@ -229,6 +229,7 @@ void _main(int argc, char *argv[])
|
||||
char *inifile = "/CProxy.conf";
|
||||
inifile = strcat(path, inifile);
|
||||
conf *configure = (struct CONF *)malloc(sizeof(struct CONF));
|
||||
memset(configure, 0, sizeof(struct CONF));
|
||||
read_conf(inifile, configure);
|
||||
|
||||
sslEncodeCode = 0; // 默认SSL不转码
|
||||
@ -241,7 +242,6 @@ void _main(int argc, char *argv[])
|
||||
if (configure->process > 0) // 如果配置文件有值,优先使用配置文件读取的值
|
||||
process = configure->process;
|
||||
|
||||
//char optstring[] = ":l:f:t:p:c:e:s:h?";
|
||||
int longindex = 0;
|
||||
char optstring[] = ":l:f:t:p:c:e:s:h?";
|
||||
static struct option longopts[] = {
|
||||
@ -257,6 +257,7 @@ void _main(int argc, char *argv[])
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
char *p = NULL;
|
||||
//char optstring[] = ":l:f:t:p:c:e:s:h?";
|
||||
//while (-1 != (opt = getopt(argc, argv, optstring))) {
|
||||
while (-1 != (opt = getopt_long(argc, argv, optstring, longopts, &longindex))) {
|
||||
switch (opt) {
|
||||
@ -313,7 +314,8 @@ void _main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
httpdns_initialize(configure); // 初始化http_dns
|
||||
server_ini(); // 守护进程
|
||||
httpdns_initialize(configure); // 初始化http_dns
|
||||
memset(cts, 0, sizeof(cts));
|
||||
for (i = MAX_CONNECTION; i--;)
|
||||
cts[i].fd = -1;
|
||||
@ -340,10 +342,9 @@ void _main(int argc, char *argv[])
|
||||
if (setegid(configure->uid) == -1 || seteuid(configure->uid) == -1) // 设置uid
|
||||
exit(1);
|
||||
|
||||
server_ini(); // 初始化http_proxy
|
||||
//start_server(configure);
|
||||
//start_server(configure); // 单线程
|
||||
//httpdns_loop(configure);
|
||||
|
||||
|
||||
pthread_t thread_id = 0;
|
||||
sigset_t signal_mask;
|
||||
sigemptyset(&signal_mask);
|
||||
@ -357,11 +358,21 @@ void _main(int argc, char *argv[])
|
||||
perror("pthread_create");
|
||||
if (pthread_create(&thread_id, NULL, &httpdns_loop, (void *)configure) != 0)
|
||||
perror("pthread_create");
|
||||
|
||||
|
||||
pthread_join(thread_id, NULL);
|
||||
pthread_exit(NULL);
|
||||
|
||||
return ;
|
||||
/* 线程分离未使用
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
pthread_create(&thread_id, &attr, &tcp_timeout_check, NULL);
|
||||
pthread_create(&thread_id, &attr, &http_proxy_loop, (void *)configure);
|
||||
pthread_create(&thread_id, &attr, &httpdns_loop, (void *)configure);
|
||||
pthread_exit(NULL);
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
Loading…
Reference in New Issue
Block a user