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

potential buffer overflow for the message size #37

Closed
joegasewicz opened this issue Jun 17, 2024 · 0 comments · Fixed by #39
Closed

potential buffer overflow for the message size #37

joegasewicz opened this issue Jun 17, 2024 · 0 comments · Fixed by #39
Labels
bug Something isn't working

Comments

@joegasewicz
Copy link
Owner

joegasewicz commented Jun 17, 2024

From skeeto on Reddit:

Instead, get the string length, allocate enough for the whole thing, then memcpy it into place. And before any of that, check for null. Technically it's undefined to pass null for %s in the printf (FMQ_LOGGER), too.

$ eval cc -g3 -fsanitize=address,undefined *.c $(pkg-config --cflags --libs libulfius jansson)
$ ./a.out

Then in another terminal:

$ curl -d @examples/sample.json http://0:8005/provider
The server crashes:

Starting server on http://localhost:8005
Received: (null)
tcp.c:71:5: runtime error: null pointer passed as argument 2, which is declared to never be null
Context:

    data->message = malloc(sizeof(char) * 1024);
    strcpy(data->message, message);

@joegasewicz joegasewicz added the bug Something isn't working label Jun 17, 2024
joegasewicz added a commit that referenced this issue Jun 18, 2024
joegasewicz added a commit that referenced this issue Jun 18, 2024
@joegasewicz joegasewicz linked a pull request Jun 18, 2024 that will close this issue
joegasewicz added a commit that referenced this issue Jun 18, 2024
@joegasewicz joegasewicz mentioned this issue Jun 18, 2024
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant