mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-05-07 20:39:34 +08:00
Clients: Fix assumption that long is >32 bits.
This commit is contained in:
@@ -68,6 +68,7 @@ int cfg_parse_property(struct mosq_config *cfg, int argc, char *argv[], int *idx
|
||||
mosquitto_property **proplist;
|
||||
int rc;
|
||||
long tmpl;
|
||||
long long tmpll;
|
||||
size_t szt;
|
||||
|
||||
/* idx now points to "command" */
|
||||
@@ -176,20 +177,20 @@ int cfg_parse_property(struct mosq_config *cfg, int argc, char *argv[], int *idx
|
||||
rc = mosquitto_property_add_int16(proplist, identifier, (uint16_t )tmpl);
|
||||
break;
|
||||
case MQTT_PROP_TYPE_INT32:
|
||||
tmpl = atol(value);
|
||||
if(tmpl < 0 || tmpl > UINT32_MAX){
|
||||
fprintf(stderr, "Error: Property value (%ld) out of range for property %s.\n\n", tmpl, propname);
|
||||
tmpll = atoll(value);
|
||||
if(tmpll < 0 || tmpll > UINT32_MAX){
|
||||
fprintf(stderr, "Error: Property value (%lld) out of range for property %s.\n\n", tmpll, propname);
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
rc = mosquitto_property_add_int32(proplist, identifier, (uint32_t )tmpl);
|
||||
rc = mosquitto_property_add_int32(proplist, identifier, (uint32_t )tmpll);
|
||||
break;
|
||||
case MQTT_PROP_TYPE_VARINT:
|
||||
tmpl = atol(value);
|
||||
if(tmpl < 0 || tmpl > UINT32_MAX){
|
||||
fprintf(stderr, "Error: Property value (%ld) out of range for property %s.\n\n", tmpl, propname);
|
||||
tmpll = atoll(value);
|
||||
if(tmpll < 0 || tmpll > UINT32_MAX){
|
||||
fprintf(stderr, "Error: Property value (%lld) out of range for property %s.\n\n", tmpll, propname);
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
rc = mosquitto_property_add_varint(proplist, identifier, (uint32_t )tmpl);
|
||||
rc = mosquitto_property_add_varint(proplist, identifier, (uint32_t )tmpll);
|
||||
break;
|
||||
case MQTT_PROP_TYPE_BINARY:
|
||||
szt = strlen(value);
|
||||
|
||||
+14
-8
@@ -226,7 +226,7 @@ static void init_config(struct mosq_config *cfg, int pub_or_sub)
|
||||
}else{
|
||||
cfg->protocol_version = MQTT_PROTOCOL_V311;
|
||||
}
|
||||
cfg->session_expiry_interval = -1; /* -1 means unset here, the user can't set it to -1. */
|
||||
cfg->session_expiry_interval = -2; /* -2 means unset here, the user can't set it to -2. */
|
||||
cfg->transport = MOSQ_T_TCP;
|
||||
}
|
||||
|
||||
@@ -481,10 +481,14 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
|
||||
#endif
|
||||
|
||||
if(cfg->protocol_version == 5){
|
||||
if(cfg->clean_session == false && cfg->session_expiry_interval == -1){
|
||||
/* User hasn't set session-expiry-interval, but has cleared clean
|
||||
* session so default to persistent session. */
|
||||
cfg->session_expiry_interval = UINT32_MAX;
|
||||
if(cfg->session_expiry_interval == -2){
|
||||
if(cfg->clean_session == false){
|
||||
/* User hasn't set session-expiry-interval, but has cleared clean
|
||||
* session so default to persistent session. */
|
||||
cfg->session_expiry_interval = UINT32_MAX;
|
||||
}else{
|
||||
cfg->session_expiry_interval = 0;
|
||||
}
|
||||
}
|
||||
if(cfg->session_expiry_interval > 0){
|
||||
if(cfg->session_expiry_interval == UINT32_MAX && (cfg->id_prefix || !cfg->id)){
|
||||
@@ -1310,19 +1314,21 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
|
||||
cfg->session_expiry_interval = UINT32_MAX;
|
||||
}else{
|
||||
char *endptr = NULL;
|
||||
cfg->session_expiry_interval = strtol(argv[i+1], &endptr, 0);
|
||||
long long llvalue = strtoll(argv[i+1], &endptr, 0);
|
||||
if(endptr == argv[i+1] || endptr[0] != '\0'){
|
||||
/* Entirety of argument wasn't a number */
|
||||
fprintf(stderr, "Error: session-expiry-interval not a number.\n\n");
|
||||
return 1;
|
||||
}
|
||||
if(cfg->session_expiry_interval > UINT32_MAX || cfg->session_expiry_interval < -1){
|
||||
if(llvalue > UINT32_MAX || llvalue < -1){
|
||||
fprintf(stderr, "Error: session-expiry-interval out of range.\n\n");
|
||||
return 1;
|
||||
}
|
||||
if(cfg->session_expiry_interval == -1){
|
||||
if(llvalue == -1LL){
|
||||
/* Convenience value for infinity. */
|
||||
cfg->session_expiry_interval = UINT32_MAX;
|
||||
}else{
|
||||
cfg->session_expiry_interval = llvalue;
|
||||
}
|
||||
}
|
||||
cfg->protocol_version = MQTT_PROTOCOL_V5;
|
||||
|
||||
@@ -119,7 +119,7 @@ struct mosq_config {
|
||||
bool pretty; /* sub, rr */
|
||||
unsigned int timeout; /* sub */
|
||||
int sub_opts; /* sub */
|
||||
long session_expiry_interval;
|
||||
int64_t session_expiry_interval;
|
||||
int random_filter; /* sub */
|
||||
int transport;
|
||||
#ifndef WIN32
|
||||
|
||||
Reference in New Issue
Block a user