From af2678ea493dce1b44d07de0f3c8e21ffdbed843 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 9 Aug 2018 22:31:03 +0100 Subject: [PATCH] Fix possible endian issue when reading the `memory_limit` option. Signed-off-by: Roger A. Light --- ChangeLog.txt | 1 + src/conf.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 42c10430..ab1202b6 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -22,6 +22,7 @@ Broker: #860. - Fix `use_identity_as_username true` not working. Closes #833. - Fix UNSUBACK messages not being logged. Closes #903. +- Fix possible endian issue when reading the `memory_limit` option. Library: - Fix some places where return codes were incorrect, including to the diff --git a/src/conf.c b/src/conf.c index 721207d5..f5e989ff 100644 --- a/src/conf.c +++ b/src/conf.c @@ -64,6 +64,7 @@ extern SERVICE_STATUS_HANDLE service_handle; static int conf__parse_bool(char **token, const char *name, bool *value, char *saveptr); static int conf__parse_int(char **token, const char *name, int *value, char *saveptr); +static int conf__parse_ssize_t(char **token, const char *name, ssize_t *value, char *saveptr); static int conf__parse_string(char **token, const char *name, char **value, char *saveptr); static int config__read_file(struct mosquitto__config *config, bool reload, const char *file, struct config_recurse *config_tmp, int level, int *lineno); static int config__check(struct mosquitto__config *config); @@ -1527,7 +1528,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct } }else if(!strcmp(token, "memory_limit")){ ssize_t lim; - if(conf__parse_int(&token, "memory_limit", (int *)&lim, saveptr)) return MOSQ_ERR_INVAL; + if(conf__parse_ssize_t(&token, "memory_limit", &lim, saveptr)) return MOSQ_ERR_INVAL; if(lim < 0){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid memory_limit value (%ld).", lim); return MOSQ_ERR_INVAL; @@ -2146,6 +2147,19 @@ static int conf__parse_int(char **token, const char *name, int *value, char *sav return MOSQ_ERR_SUCCESS; } +static int conf__parse_ssize_t(char **token, const char *name, ssize_t *value, char *saveptr) +{ + *token = strtok_r(NULL, " ", &saveptr); + if(*token){ + *value = atol(*token); + }else{ + log__printf(NULL, MOSQ_LOG_ERR, "Error: Empty %s value in configuration.", name); + return MOSQ_ERR_INVAL; + } + + return MOSQ_ERR_SUCCESS; +} + static int conf__parse_string(char **token, const char *name, char **value, char *saveptr) { *token = strtok_r(NULL, "", &saveptr);