Skip to content

Commit

Permalink
more fix of memory access
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Jul 26, 2020
1 parent 5f907e3 commit e8daf7c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
{
return -1;
}
if(data_len>=max_data_len+1)
{
mylog(log_debug,"data_len=%d >= max_data_len+1,ignored",data_len);
return -1;
}
if(!recv_info.new_src_ip.equal(send_info.new_dst_ip)||recv_info.src_port!=send_info.dst_port)
{
mylog(log_debug,"unexpected adress %s %s %d %d\n",recv_info.new_src_ip.get_str1(),send_info.new_dst_ip.get_str2(),recv_info.src_port,send_info.dst_port);
Expand Down
9 changes: 8 additions & 1 deletion connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ int recv_bare(raw_info_t &raw_info,char* & data,int & len)//recv function with e
//printf("recv_raw_fail in recv bare\n");
return -1;
}

if(len>=max_data_len+1)
{
mylog(log_debug,"data_len=%d >= max_data_len+1,ignored",len);
return -1;
}

mylog(log_trace,"data len=%d\n",len);
if ((raw_mode == mode_faketcp && (recv_info.syn == 1 || recv_info.ack != 1)))
{
Expand Down Expand Up @@ -615,7 +622,7 @@ int reserved_parse_safer(conn_info_t &conn_info,const char * input,int input_len
}


if(after_recv_raw0(conn_info.raw_info)!=0) return -1;
if(after_recv_raw0(conn_info.raw_info)!=0) return -1; //TODO might need to move this function to somewhere else after --fix-gro is introduced

return 0;
}
Expand Down
3 changes: 1 addition & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ PCAP="-lpcap"
MP="-DUDP2RAW_MP"



NAME=udp2raw

TARGETS=amd64 arm amd64_hw_aes arm_asm_aes mips24kc_be mips24kc_be_asm_aes x86 x86_asm_aes mips24kc_le mips24kc_le_asm_aes
Expand Down Expand Up @@ -59,7 +58,7 @@ debug: git_version
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -D MY_DEBUG
debug2: git_version
rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -ggdb
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -ggdb -fsanitize=address

#targets only for 'make release'

Expand Down
2 changes: 1 addition & 1 deletion network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ int pre_recv_raw_packet()
}
}

if(g_packet_buf_len> max_data_len+1)
if(g_packet_buf_len>= max_data_len+1)
{
if(g_fix_gro==0)
{
Expand Down
4 changes: 2 additions & 2 deletions pcap_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

struct bpf_program
{
char a[2000];
char a[4096];
};

struct pcap_t
{
char a[2000];
char a[4096];
};

typedef unsigned int bpf_u_int32;
Expand Down
5 changes: 5 additions & 0 deletions server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ int server_on_raw_recv_multi() //called when server received an raw packet
{
return 0;
}
if(data_len>=max_data_len+1)
{
mylog(log_debug,"data_len=%d >= max_data_len+1,ignored",data_len);
return -1;
}
if(use_tcp_dummy_socket!=0)
return 0;
raw_info_t &raw_info=tmp_raw_info;
Expand Down

0 comments on commit e8daf7c

Please sign in to comment.