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

Unused variables in l_equals? #1

Closed
kyzentun opened this issue May 5, 2020 · 1 comment
Closed

Unused variables in l_equals? #1

kyzentun opened this issue May 5, 2020 · 1 comment

Comments

@kyzentun
Copy link

kyzentun commented May 5, 2020

l_equals contains this code:

    if (hex)
    {
        unsigned char *_hash1 = malloc(len1 / 2);
        unsigned char *_hash2 = malloc(len2 / 2);

        from_hex(hash1, _hash1, len1);
        from_hex(hash2, _hash2, len2);

        int cmp = memcmp(hash1, hash2, len1);
        lua_pushboolean(L, cmp == 0);

        free((void *)_hash1);
        free((void *)_hash2);
    }

If I understand correctly, this creates two variables to store the raw binary form of each hash. Then converts the hashes to binary and stores them in the new variables.
The memcmp runs on the original hex forms of the hashes, leaving the binary variables unused.
So is this two unused memory allocations, or is there something I'm not seeing?

The allocation and hex conversion would take longer than running memcmp on the hex, so there's no reason to convert to binary first.

@cryi
Copy link
Contributor

cryi commented Aug 4, 2022

Hi. Yea you are right. Sorry I did not notice it sooner. Not sure why I did not get notified.

Anyway patched and updated to mbedtls 3. And thank you! 🙂

@cryi cryi closed this as completed Aug 4, 2022
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