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

[Linux] Uninitialized bytes being passed to write() #82

Open
urlofmar opened this issue Apr 8, 2024 · 0 comments
Open

[Linux] Uninitialized bytes being passed to write() #82

urlofmar opened this issue Apr 8, 2024 · 0 comments

Comments

@urlofmar
Copy link

urlofmar commented Apr 8, 2024

On Linux, valgrind complains about uninitialized bytes being passed to write():

==14689== Syscall param write(buf) points to uninitialised byte(s)
==14689==    at 0x5C6132F: __libc_write (write.c:26)
==14689==    by 0x5C6132F: write (write.c:24)
==14689==    by 0x5656A09: cppcoro::detail::linux::message_queue::enqueue_message(void*, cppcoro::detail::linux::message_type) (linux.cpp:78)
==14689==    by 0x564FB0B: cppcoro::io_service::post_wake_up_event() (io_service.cpp:748)
==14689==    by 0x564F564: cppcoro::io_service::stop() (io_service.cpp:454)
...
==14689==  Address 0x1ffefff044 is on thread 1's stack
==14689==  in frame #1, created by cppcoro::detail::linux::message_queue::enqueue_message(void*, cppcoro::detail::linux::message_type) (linux.cpp:74)

The write() call is in

bool message_queue::enqueue_message(void* msg, message_type type)
{
    message qmsg;
    qmsg.m_type = type;
    qmsg.m_ptr = msg;
    int status = write(m_pipefd[1], (const char*)&qmsg, sizeof(message));
    return status==-1?false:true;
}

where

struct message
{
    enum message_type m_type;
    void* m_ptr;
};

has padding bytes between its two members. These bytes are not initialized in qmsg, but still being written.

So the easiest solution would be to initialize all of qmsg's bytes:

    message qmsg;
+   std::memset(&qmsg, 0, sizeof(qmsg));
    qmsg.m_type = type;
    qmsg.m_ptr = msg;
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