mqtt3_db_message_timeout_check just initialize new_state out of loop

Bug #1324411 reported by chenzhenianqing
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mosquitto
Fix Released
Undecided
Unassigned

Bug Description

hi ,

in mqtt3_db_message_timeout_check, we just init new_state once before the function , bug changeed && used in the loop,

it may be no bugs in reality, bug the code should better init new_state = mosq_ms_invalid; in the for、while loop.
 maybe we need init it in the while loop .

int mqtt3_db_message_timeout_check(struct mosquitto_db *db, unsigned int timeout)
{
        int i;
        time_t threshold;
        enum mosquitto_msg_state new_state = mosq_ms_invalid;
        struct mosquitto *context;
        struct mosquitto_client_msg *msg;

        threshold = mosquitto_time() - timeout;

        for(i=0; i<db->context_count; i++){
                context = db->contexts[i];
                if(!context) continue;

                msg = context->msgs;
                while(msg){

//add this line to init it every time.
new_state = mosq_ms_invalid;

                        if(msg->timestamp < threshold && msg->state != mosq_ms_queued){
                                switch(msg->state){
                                        case mosq_ms_wait_for_puback:
                                                new_state = mosq_ms_publish_qos1;
                                                break;
                                        case mosq_ms_wait_for_pubrec:
                                                new_state = mosq_ms_publish_qos2;
                                                break;
                                        case mosq_ms_wait_for_pubrel:
                                                new_state = mosq_ms_send_pubrec;
                                                break;
                                        case mosq_ms_wait_for_pubcomp:
                                                new_state = mosq_ms_resend_pubrel;
                                                break;
                                        default:
                                                break;
                                }
                                if(new_state != mosq_ms_invalid){
                                        msg->timestamp = mosquitto_time();
                                        msg->state = new_state;
                                        msg->dup = true;
                                }
                        }
                        msg = msg->next;
                }
        }

        return MOSQ_ERR_SUCCESS;
}

Revision history for this message
Roger Light (roger.light) wrote :

I agree, this doesn't look quite right but in practice probably didn't affect anything.

I've commited a change that fixes it.

Changed in mosquitto:
milestone: none → 1.4
status: New → Fix Committed
Revision history for this message
chenzhenianqing (hw-henry2008) wrote :

many thanks

Changed in mosquitto:
milestone: 1.4 → 1.3.2
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.