Skip to content

Commit

Permalink
feat: argument validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Chion82 committed Sep 6, 2017
1 parent 78289d5 commit a635839
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 139,13 @@ int main(int argc, char* argv[]) {
vector_init(&open_connections_vector);

if (argc < 5) {
printf("Usage: kcpraw_client SERVER_IP SERVER_PORT LOCAL_IP LISTEN_PORT [--mode MODE] [--key KEY] [--noseq] [--bpf]\n");
printf("Usage: kcpraw_client SERVER_IP SERVER_PORT LISTEN_IP LISTEN_PORT [--mode MODE] [--key KEY] [--noseq] [--bpf]\n");
exit(1);
}

validate_arg(argv[1], 128);
validate_arg(argv[3], 128);

last_recv_heart_beat = 0;
last_kcp_recv = getclock();

Expand Down
7 changes: 7 additions & 0 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 668,10 @@ int update_src_addr() {
close(probe_sock);
return 0;
}

void validate_arg(const char* arg, int max_len) {
if (strlen(arg) > max_len) {
printf("Invalid argument: %s\n", arg);
exit(1);
}
}
2 changes: 2 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 112,5 @@ int init_connect_to_socket();
void enable_bpf(int argc, char* argv[]);
void init_bpf();
int update_src_addr();

void validate_arg(const char* arg, int max_len);
3 changes: 3 additions & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 73,9 @@ int main(int argc, char* argv[]) {
exit(1);
}

validate_arg(argv[1], 128);
validate_arg(argv[3], 128);

last_recv_heart_beat = 0;
last_kcp_recv = getclock();

Expand Down

0 comments on commit a635839

Please sign in to comment.