Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integer overflow ? #400

Open
cbucher opened this issue Feb 23, 2023 · 3 comments
Open

integer overflow ? #400

cbucher opened this issue Feb 23, 2023 · 3 comments

Comments

@cbucher
Copy link
Contributor

cbucher commented Feb 23, 2023

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

We can see that the "custom" entrie of the log_val_type enum is set to 999. However, when this value is serialized, it
is cast as 8bit unsigned integer which maximum value 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;
    }

Perhaps, the enum could be defined as :

enum log_val_type : byte {
    app_log         = 1,
    conf            = 2,
    cluster_server  = 3,
    log_pack        = 4,
    snp_sync_req    = 5,
    custom          = 999,
};
@greensky00
Copy link
Contributor

Hi @cbucher , thanks for bringing up this issue. Actually it was already reported before #349 and then forgotten.

I'd rather prefer changing it like this:

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

given that 999 % 256 = 231. Would you like to submit a PR? Or let me know if you want me to do it.

@cbucher
Copy link
Contributor Author

cbucher commented Mar 2, 2023

Hi,

Yes I will submit a PR.

@cbucher
Copy link
Contributor Author

cbucher commented Mar 8, 2023

Hi @greensky00 , I have submitted a PR #404

Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants