Reject oversized service strings and cover scalar bounds

This commit is contained in:
evgeny committed 2026-10-26 09:08:23 +01:00
1 parent f1388d8822
commit db2c88f7d9
2 files changed
+12 -18

No files matched your search

+6 -17
View File
@@ -790,14 +790,10 @@ static int parse_size_with_suffix(const char *value, uint64_t *out_bytes) {
static int parse_chatserver(const char *key, const char *value, struct global_config *global, const char *filename, int line_num) {
if (strcmp(key, "join_password") == 0) {
strncpy(global->chatserver_join_password, value, sizeof(global->chatserver_join_password) - 1);
global->chatserver_join_password[sizeof(global->chatserver_join_password) - 1] = '\0';
return 0;
return assign_string(global->chatserver_join_password, sizeof(global->chatserver_join_password), value);
}
if (strcmp(key, "allowed_groups") == 0) {
strncpy(global->chatserver_allowed_groups, value, sizeof(global->chatserver_allowed_groups) - 1);
global->chatserver_allowed_groups[sizeof(global->chatserver_allowed_groups) - 1] = '\0';
return 0;
return assign_string(global->chatserver_allowed_groups, sizeof(global->chatserver_allowed_groups), value);
}
if (strcmp(key, "storage_total_size") == 0) {
uint64_t sz;
@@ -818,19 +814,13 @@ static int parse_chatserver(const char *key, const char *value, struct global_co
return 0;
}
if (strcmp(key, "headless_control_bind") == 0) {
strncpy(global->headless_control_bind, value, sizeof(global->headless_control_bind) - 1);
global->headless_control_bind[sizeof(global->headless_control_bind) - 1] = '\0';
return 0;
return assign_string(global->headless_control_bind, sizeof(global->headless_control_bind), value);
}
if (strcmp(key, "call_audio_bind") == 0) {
strncpy(global->call_audio_bind, value, sizeof(global->call_audio_bind) - 1);
global->call_audio_bind[sizeof(global->call_audio_bind) - 1] = '\0';
return 0;
return assign_string(global->call_audio_bind, sizeof(global->call_audio_bind), value);
}
if (strcmp(key, "radio_audio_bind") == 0) {
strncpy(global->radio_audio_bind, value, sizeof(global->radio_audio_bind) - 1);
global->radio_audio_bind[sizeof(global->radio_audio_bind) - 1] = '\0';
return 0;
return assign_string(global->radio_audio_bind, sizeof(global->radio_audio_bind), value);
}
return -1;
}
@@ -1160,8 +1150,7 @@ struct utun_config* parse_config_from_buf(const char *buf, size_t len, const cha
} else if (strcmp(key, "netif") == 0) {
cfg->global.tcp_proxy_server_netif_index = get_netif_index(value);
} else if (strcmp(key, "bind_ip") == 0) {
strncpy(cfg->global.tcp_proxy_server_bind_ip, value, sizeof(cfg->global.tcp_proxy_server_bind_ip) - 1);
cfg->global.tcp_proxy_server_bind_ip[sizeof(cfg->global.tcp_proxy_server_bind_ip) - 1] = '\0';
option_result = assign_string(cfg->global.tcp_proxy_server_bind_ip, sizeof(cfg->global.tcp_proxy_server_bind_ip), value);
} else if (strcmp(key, "connect_timeout") == 0) {
option_result = parse_integer(value, 0, INT_MAX / 10, &cfg->global.tcp_proxy_server_connect_timeout_ms);
} else {
+6 -1
View File
@@ -63,7 +63,12 @@ static void test_rejections(void) {
"[chat]\nstorage_total_size=18446744073709551616\n", "[chat]\nstorage_total_size=17179869184G\n",
"[allowed_keys]\nkey=bad\n", "[network:n]\nid=100000000000000\n", "[network:n]\npubkey=1g\n",
"[network:n]\nid=1\n", "[ntp]\nserver=\n", "[tcp_proxy_client]\nforward=0 -> 1.2.3.4:80\n",
"[server:s]\ninvalid\n"
"[server:s]\ninvalid\n", "[global]\nkeepalive_interval=65536\n", "[global]\nclient_type=256\n",
"[global]\nmtu=1280junk\n", "[global]\ndb_sync_ttl=-1\n", "[global]\nauto_sockets=maybe\n",
"[global]\nkeepalive_timeout=999999999999999999999999\n", "[reality]\ntime_window=3601\n",
"[reality]\nrelay_idle_timeout=214749\n", "[tcp_proxy_server]\nconnect_timeout=-1\n",
"[tcp_proxy_client]\nforward=80junk -> 127.0.0.1:80\n", "[tcp_proxy_client]\nforward=80 -> localhost:80\n",
"[ntp]\ninterval=214749\n", "[ntp]\nenabled=maybe\n", "[socks]\nenabled=maybe\n"
};
char path[] = "/tmp/utun-parser-contract-XXXXXX";
int fd = mkstemp(path); assert(fd >= 0); close(fd);