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

memset typo in md5.c #1

Open
philburk opened this issue Aug 6, 2013 · 0 comments
Open

memset typo in md5.c #1

philburk opened this issue Aug 6, 2013 · 0 comments

Comments

@philburk
Copy link

philburk commented Aug 6, 2013

src/libFLAC/md5.c, line 266 you can find:

memset(ctx, 0, sizeof(ctx));    /* In case it's sensitive */
if(0 != ctx->internal_buf) {
    free(ctx->internal_buf);
    ctx->internal_buf = 0;
    ctx->capacity = 0;
}

That memset does not clear the entire structure. It only clears 4 or 8 bytes, depending on the size of the ctx pointer. It should use sizeof(*ctx) not sizeof(ctx). This is old bug from the original md5.c.

Note that the code that follows relies on the bug. If the memset bug is fixed then there could be a memory leak of the internal_buf. I suggest that the memset should be fixed and moved after the internal_buf code.

This should work:

if(0 != ctx->internal_buf) {
    free(ctx->internal_buf);
    ctx->internal_buf = 0;
    ctx->capacity = 0;
}
memset(ctx, 0, sizeof(*ctx));   /* In case it's sensitive */
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

1 participant