8000 Crash when string length is negative · Issue #9 · Steve132/ubj · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Crash when string length is negative #9

869E
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

Open
to-miz opened this issue Jul 20, 2022 · 0 comments
Open

Crash when string length is negative #9

to-miz opened this issue Jul 20, 2022 · 0 comments

Comments

@to-miz
Copy link
to-miz commented Jul 20, 2022

When using negative lengths for strings there is a crash. There seems to be no validation on the string length or the result of malloc, so negative or huge values can result in a crash.

Minimal example program:

#include "stdio.h"
#include "ubj.h"
#include "ubjr.c"

int main()
{
    char test[258] = {'S', 'i', -1, 't'};
    for (int i = 3; i < 258; ++i)
    {
        test[i] = 't';
    }
    ubjr_context_t *ctx = ubjr_open_memory((const uint8_t *)test, (const uint8_t *)(test + sizeof(test)));
    ubjr_dynamic_t value = ubjr_read_dynamic(ctx);
    if (value.type == UBJ_STRING)
    {
        printf("%s\n", value.string);
    }
    else
    {
        printf("ERROR\n");
    }
    ubjr_cleanup_dynamic(&value);
    ubjr_close_context(ctx);
    return 0;
}
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
0