Fix possible endian issue when reading the `memory_limit` option.

Signed-off-by: Roger A. Light <roger@atchoo.org>
pull/932/head
Roger A. Light 7 years ago
parent 945b3283a6
commit af2678ea49

@ -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

@ -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);

Loading…
Cancel
Save