Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2894,8 +2894,12 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload,
if(conf__parse_int(&token, token, &tmp_int, &saveptr)){
return MOSQ_ERR_INVAL;
}
if(tmp_int < 0 || tmp_int > UINT16_MAX){
log__printf(NULL, MOSQ_LOG_WARNING, "Error: Packet buffer size must be between 0 and 65535 inclusive.");
/* A buffer of size 0 can never hold the NUL terminator that
* http__read() and the packet reading code both assume is
* always present, so it isn't a usable value here even
* though it fits in the uint16_t range. */
if(tmp_int < 1 || tmp_int > UINT16_MAX){
log__printf(NULL, MOSQ_LOG_WARNING, "Error: Packet buffer size must be between 1 and 65535 inclusive.");
return MOSQ_ERR_INVAL;
}
config->packet_buffer_size = (uint16_t)tmp_int;
Expand Down
5 changes: 3 additions & 2 deletions test/broker/16-config-parse-errors-without-tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
do_test_broker_failure(conf_file, ["mount_point test/"], port, 3, "Error: The 'mount_point' option requires a listener to be defined first.") # Missing listener config
do_test_broker_failure(conf_file, [f"listener {port}","mount_point test/+/"], port, 3, "Error: Invalid 'mount_point' value (test/+/). Does it contain a wildcard character?") # Wildcard in mount point.
do_test_broker_failure(conf_file, [f"listener 100000"], port, 3, "Error: Invalid 'port' value (100000).") # Out of range
do_test_broker_failure(conf_file, [f"listener {port}","packet_buffer_size 0"], port, 3, "Error: Packet buffer size must be between 1 and 65535 inclusive.") # A zero-sized buffer can never hold the NUL terminator http__read() assumes is there
if mosq_test.check_features(["WITH_UNIX_SOCKETS"]):
do_test_broker_failure(conf_file, [f"listener 0"], port, 3, "Error: A listener with port 0 must provide a Unix socket path.") # Missing unix socket
do_test_broker_failure(conf_file, [f"listener {port}","protocol"], port, 3, "Error: Empty 'protocol' value in configuration.") # Empty proto
Expand Down Expand Up @@ -86,8 +87,8 @@
do_test_broker_failure(conf_file, [f"listener {port}", "max_topic_alias_broker -1"], port, 3, "Error: Invalid 'max_topic_alias_broker' value in configuration.") # Invalid value
do_test_broker_failure(conf_file, [f"listener {port}", "listener_auto_id_prefix"], port, 3, "Error: Empty 'listener_auto_id_prefix' value in configuration.") # Empty string
do_test_broker_failure(conf_file, [f"listener {port}", f"listener_auto_id_prefix {'a'*51}"], port, 3, "Error: 'listener_auto_id_prefix' length must be <= 50.") # Invalid value
do_test_broker_failure(conf_file, ["websockets_headers_size 65536"], port, 3, "Error: Packet buffer size must be between 0 and 65535 inclusive.") # Invalid value
do_test_broker_failure(conf_file, ["websockets_headers_size -1"], port, 3, "Error: Packet buffer size must be between 0 and 65535 inclusive.") # Invalid value
do_test_broker_failure(conf_file, ["websockets_headers_size 65536"], port, 3, "Error: Packet buffer size must be between 1 and 65535 inclusive.") # Invalid value
do_test_broker_failure(conf_file, ["websockets_headers_size -1"], port, 3, "Error: Packet buffer size must be between 1 and 65535 inclusive.") # Invalid value
do_test_broker_failure(conf_file, ["memory_limit -1"], port, 3, "Error: Invalid 'memory_limit' value (-1).") # Invalid value

do_test_broker_failure(conf_file, ["sys_interval -1"], port, 3, "Error: Invalid 'sys_interval' value (-1).") # Invalid value
Expand Down