NuRaft icon indicating copy to clipboard operation
NuRaft copied to clipboard

value overflow in serialize of log_entry

Open tobecontinued opened this issue 3 years ago • 1 comments

hi @greensky00 , I found a potenal issue, could you pls have a look.

In log_val_type , custom is set to 999

enum log_val_type {
    app_log         = 1,
    conf            = 2,
    cluster_server  = 3,
    log_pack        = 4,
    snp_sync_req    = 5,
    custom          = 999,
};

But log_entry uses uint8 to store the value_type_ whose type is value_type_, but max of uint8 is 255.

    ptr<buffer> serialize() {
        buff_->pos(0);
        ptr<buffer> buf = buffer::alloc( sizeof(ulong) +
                                         sizeof(char) +
                                         buff_->size() );
        buf->put(term_);
        buf->put( (static_cast<byte>(value_type_)) );
        buf->put(*buff_);
        buf->pos(0);
        return buf;
    }

tobecontinued avatar Apr 12 '22 13:04 tobecontinued

Thanks, let me think of the fix without hurting the backward compatibility.

greensky00 avatar Apr 13 '22 04:04 greensky00