diff --git a/client/client_shared.c b/client/client_shared.c index 091bd799..bca837ed 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -689,8 +689,8 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c return 1; }else{ cfg->keepalive = atoi(argv[i+1]); - if(cfg->keepalive>65535){ - fprintf(stderr, "Error: Invalid keepalive given: %d\n", cfg->keepalive); + if(cfg->keepalive<5 || cfg->keepalive>UINT16_MAX){ + fprintf(stderr, "Error: Invalid keepalive given, it must be between 5 and 65535 inclusive.\n\n"); return 1; } } diff --git a/lib/connect.c b/lib/connect.c index efe82907..ddec8210 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -43,7 +43,7 @@ static int mosquitto__connect_init(struct mosquitto *mosq, const char *host, int if(!mosq) return MOSQ_ERR_INVAL; if(!host || port < 0 || port > UINT16_MAX) return MOSQ_ERR_INVAL; - if(keepalive < 5 || keepalive > UINT16_MAX) return MOSQ_ERR_INVAL; + if(keepalive != 0 && (keepalive < 5 || keepalive > UINT16_MAX)) return MOSQ_ERR_INVAL; /* Only MQTT v3.1 requires a client id to be sent */ if(mosq->id == NULL && (mosq->protocol == mosq_p_mqtt31)){