Fix segfault on unrecognized option

This commit is contained in:
Vadim Vetrov 2024-08-10 00:40:31 +03:00
parent 6bbeae3876
commit 8e592d8957
No known key found for this signature in database
GPG Key ID: E8A308689D7A73A5

View File

@ -65,6 +65,11 @@ struct config_t config = {
static long parse_numeric_option(const char* value) { static long parse_numeric_option(const char* value) {
errno = 0; errno = 0;
if (*value == '\0') {
errno = EINVAL;
return 0;
}
char* end; char* end;
long result = strtol(value, &end, 10); long result = strtol(value, &end, 10);
if (*end != '\0') { if (*end != '\0') {
@ -208,7 +213,6 @@ static int parse_args(int argc, char *argv[]) {
config.fake_sni_ttl = num; config.fake_sni_ttl = num;
break; break;
default: default:
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error; goto error;
} }
} }