Fix segfault bufs, update coding style

This commit is contained in:
Vadim Vetrov 2024-08-12 15:22:04 +03:00
parent 24826f851d
commit 219062aae2
No known key found for this signature in database
GPG Key ID: E8A308689D7A73A5

39
args.c
View File

@ -136,10 +136,10 @@ int parse_args(int argc, char *argv[]) {
switch (opt) { switch (opt) {
case 'h': case 'h':
print_usage(argv[0]); print_usage(argv[0]);
goto out; goto stop_exec;
case 'v': case 'v':
print_version(); print_version();
goto out; goto stop_exec;
case OPT_SILENT: case OPT_SILENT:
config.verbose = 0; config.verbose = 0;
break; break;
@ -153,7 +153,6 @@ int parse_args(int argc, char *argv[]) {
config.domains_str = optarg; config.domains_str = optarg;
config.domains_strlen = strlen(config.domains_str); config.domains_strlen = strlen(config.domains_str);
break; break;
case OPT_FRAG: case OPT_FRAG:
if (strcmp(optarg, "tcp") == 0) { if (strcmp(optarg, "tcp") == 0) {
@ -163,7 +162,7 @@ int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "none") == 0) { } else if (strcmp(optarg, "none") == 0) {
config.fragmentation_strategy = FRAG_STRAT_NONE; config.fragmentation_strategy = FRAG_STRAT_NONE;
} else { } else {
goto error; goto invalid_opt;
} }
break; break;
@ -173,8 +172,7 @@ int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "0") == 0) { } else if (strcmp(optarg, "0") == 0) {
config.frag_sni_faked = 0; config.frag_sni_faked = 0;
} else { } else {
errno = EINVAL; goto invalid_opt;
goto error;
} }
break; break;
@ -184,8 +182,7 @@ int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "0") == 0) { } else if (strcmp(optarg, "0") == 0) {
config.frag_sni_reverse = 0; config.frag_sni_reverse = 0;
} else { } else {
errno = EINVAL; goto invalid_opt;
goto error;
} }
break; break;
@ -195,15 +192,14 @@ int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "ttl") == 0) { } else if (strcmp(optarg, "ttl") == 0) {
config.faking_strategy = FAKE_STRAT_TTL; config.faking_strategy = FAKE_STRAT_TTL;
} else { } else {
errno = EINVAL; goto invalid_opt;
goto error;
} }
break; break;
case OPT_FAKING_TTL: case OPT_FAKING_TTL:
num = parse_numeric_option(optarg); num = parse_numeric_option(optarg);
if (errno != 0 || num < 0 || num > 255) { if (errno != 0 || num < 0 || num > 255) {
goto error; goto invalid_opt;
} }
config.faking_ttl = num; config.faking_ttl = num;
@ -215,15 +211,14 @@ int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "0") == 0) { } else if (strcmp(optarg, "0") == 0) {
config.fake_sni = 0; config.fake_sni = 0;
} else { } else {
errno = EINVAL; goto invalid_opt;
goto error;
} }
break; break;
case OPT_FAKE_SNI_SEQ_LEN: case OPT_FAKE_SNI_SEQ_LEN:
num = parse_numeric_option(optarg); num = parse_numeric_option(optarg);
if (errno != 0 || num < 0 || num > 255) { if (errno != 0 || num < 0 || num > 255) {
goto error; goto invalid_opt;
} }
config.fake_sni_seq_len = num; config.fake_sni_seq_len = num;
@ -231,7 +226,7 @@ int parse_args(int argc, char *argv[]) {
case OPT_FK_WINSIZE: case OPT_FK_WINSIZE:
num = parse_numeric_option(optarg); num = parse_numeric_option(optarg);
if (errno != 0 || num < 0) { if (errno != 0 || num < 0) {
goto error; goto invalid_opt;
} }
config.fk_winsize = num; config.fk_winsize = num;
@ -239,7 +234,7 @@ int parse_args(int argc, char *argv[]) {
case OPT_SEG2DELAY: case OPT_SEG2DELAY:
num = parse_numeric_option(optarg); num = parse_numeric_option(optarg);
if (errno != 0 || num < 0) { if (errno != 0 || num < 0) {
goto error; goto invalid_opt;
} }
config.seg2_delay = num; config.seg2_delay = num;
@ -247,7 +242,7 @@ int parse_args(int argc, char *argv[]) {
case OPT_THREADS: case OPT_THREADS:
num = parse_numeric_option(optarg); num = parse_numeric_option(optarg);
if (errno != 0 || num < 0 || num > MAX_THREADS) { if (errno != 0 || num < 0 || num > MAX_THREADS) {
goto error; goto invalid_opt;
} }
config.threads = num; config.threads = num;
@ -255,7 +250,7 @@ int parse_args(int argc, char *argv[]) {
case OPT_QUEUE_NUM: case OPT_QUEUE_NUM:
num = parse_numeric_option(optarg); num = parse_numeric_option(optarg);
if (errno != 0 || num < 0) { if (errno != 0 || num < 0) {
goto error; goto invalid_opt;
} }
config.queue_start_num = num; config.queue_start_num = num;
@ -266,14 +261,16 @@ int parse_args(int argc, char *argv[]) {
} }
// out:
errno = 0; errno = 0;
return 0; return 0;
out: stop_exec:
errno = 0; errno = 0;
return 1; return 1;
error:
invalid_opt:
printf("Invalid option %s\n", long_opt[optIdx].name); printf("Invalid option %s\n", long_opt[optIdx].name);
error:
print_usage(argv[0]); print_usage(argv[0]);
errno = EINVAL; errno = EINVAL;
return -1; return -1;