Be more tolerant when loading persistence files.

pull/1694/head
Roger A. Light 6 years ago
parent ff2b111cb3
commit c5d6f32341

@ -121,6 +121,12 @@ static int persist__client_msg_restore(struct mosquitto_db *db, struct P_client_
return MOSQ_ERR_SUCCESS;
}
context = persist__find_or_add_context(db, chunk->client_id, 0);
if(!context){
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Persistence file contains client message with no matching client. File may be corrupt.");
return 0;
}
cmsg = mosquitto__calloc(1, sizeof(struct mosquitto_client_msg));
if(!cmsg){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory.");
@ -141,13 +147,6 @@ static int persist__client_msg_restore(struct mosquitto_db *db, struct P_client_
cmsg->store = load->store;
db__msg_store_ref_inc(cmsg->store);
context = persist__find_or_add_context(db, chunk->client_id, 0);
if(!context){
mosquitto__free(cmsg);
log__printf(NULL, MOSQ_LOG_ERR, "Error restoring persistent database, message store corrupt.");
return 1;
}
if(cmsg->direction == mosq_md_out){
msg_data = &context->msgs_out;
}else{
@ -186,9 +185,13 @@ static int persist__client_chunk_restore(struct mosquitto_db *db, FILE *db_fptr)
}else{
rc = persist__chunk_client_read_v234(db_fptr, &chunk, db_version);
}
if(rc){
if(rc > 0){
fclose(db_fptr);
return rc;
}else if(rc < 0){
/* Client not loaded, but otherwise not an error */
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Empty client entry found in persistence database, it may be corrupt.");
return MOSQ_ERR_SUCCESS;
}
context = persist__find_or_add_context(db, chunk.client_id, chunk.F.last_mid);

@ -74,8 +74,10 @@ int persist__chunk_client_read_v5(FILE *db_fptr, struct P_client *chunk)
chunk->F.id_len = ntohs(chunk->F.id_len);
rc = persist__read_string_len(db_fptr, &chunk->client_id, chunk->F.id_len);
if(rc || !chunk->client_id){
if(rc){
return 1;
}else if(chunk->client_id == NULL){
return -1;
}else{
return MOSQ_ERR_SUCCESS;
}

@ -175,6 +175,12 @@ static int persist__client_save(struct mosquitto_db *db, FILE *db_fptr)
chunk.F.id_len = strlen(context->id);
chunk.client_id = context->id;
if(chunk.F.id_len == 0){
/* This should never happen, but in case we have a client with
* zero length ID, don't persist them. */
continue;
}
rc = persist__chunk_client_write_v5(db_fptr, &chunk);
if(rc){
return rc;

Loading…
Cancel
Save