Skip to content

MSAN: use-of-uninitialized-value with formatDateTime #47291

@Algunenano

Description

@Algunenano

Describe the bug

A link to the report

How to reproduce

Reproduced with MSAN build in master (3503b3a).

Original reproducer:

SELECT formatDateTime(toDateTime('2018-01-02 22:33:44'), '%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W%W%W\0W%W%W%W%W%W')

Simplified reproducer:

SELECT formatDateTime(toDateTime('2018-01-02 22:33:44'), '%W%W\0')

Error message and/or stacktrace
You can find additional information in server logs.

Uninitialized bytes in __interceptor_send at offset 1077 inside [0x7fb43873e000, 1165)
==83966==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x5a90b582 in Poco::Net::SocketImpl::sendBytes(void const*, int, int) build_msan/./base/poco/Net/src/SocketImpl.cpp:290:8
    #1 0x5a9224e7 in Poco::Net::StreamSocketImpl::sendBytes(void const*, int, int) build_msan/./base/poco/Net/src/StreamSocketImpl.cpp:63:23
    #2 0x4843c3cd in DB::WriteBufferFromPocoSocket::nextImpl() build_msan/./src/IO/WriteBufferFromPocoSocket.cpp:63:34
    #3 0x4dbd74df in DB::WriteBuffer::next() build_msan/./src/IO/WriteBuffer.h:49:13
    #4 0x4dbd74df in DB::TCPHandler::sendData(DB::Block const&) build_msan/./src/Server/TCPHandler.cpp:1876:37
    #5 0x4dbcf2e8 in DB::TCPHandler::processOrdinaryQueryWithProcessors() build_msan/./src/Server/TCPHandler.cpp:842:21
    #6 0x4dbae739 in DB::TCPHandler::runImpl() build_msan/./src/Server/TCPHandler.cpp:435:17
    #7 0x4dbf6fae in DB::TCPHandler::run() build_msan/./src/Server/TCPHandler.cpp:1999:9
    #8 0x5a92611d in Poco::Net::TCPServerConnection::start() build_msan/./base/poco/Net/src/TCPServerConnection.cpp:43:3
    #9 0x5a9274cf in Poco::Net::TCPServerDispatcher::run() build_msan/./base/poco/Net/src/TCPServerDispatcher.cpp:115:20
    #10 0x5b0bb912 in Poco::PooledThread::run() build_msan/./base/poco/Foundation/src/ThreadPool.cpp:188:14
    #11 0x5b0b6d41 in Poco::(anonymous namespace)::RunnableHolder::run() build_msan/./base/poco/Foundation/src/Thread.cpp:45:11
    #12 0x5b0b2928 in Poco::ThreadImpl::runnableEntry(void*) build_msan/./base/poco/Foundation/src/Thread_POSIX.cpp:335:27
    #13 0x7fb6c70ebbb4 in start_thread /usr/src/debug/glibc/glibc/nptl/pthread_create.c:444:8
    #14 0x7fb6c716dd8f in clone3 /usr/src/debug/glibc/glibc/misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

  Uninitialized value was created by a heap allocation
    #0 0xce6cade in malloc (/mnt/ch/ClickHouse/build_msan/programs/clickhouse+0xce6cade) (BuildId: 19ce245338f9a39888754ad6e49bb9df85146cfc)
    #1 0x2a4fd167 in Allocator<false, false>::allocNoTrack(unsigned long, unsigned long) build_msan/./src/Common/Allocator.h:237:27
    #2 0x2a4fcb35 in Allocator<false, false>::alloc(unsigned long, unsigned long) build_msan/./src/Common/Allocator.h:103:16
    #3 0x2a732ce6 in DB::Memory<Allocator<false, false>>::alloc(unsigned long) build_msan/./src/IO/BufferWithOwnMemory.h:130:49
    #4 0x4843dcec in DB::Memory<Allocator<false, false>>::Memory(unsigned long, unsigned long) build_msan/./src/IO/BufferWithOwnMemory.h:49:9
    #5 0x4843dcec in DB::BufferWithOwnMemory<DB::WriteBuffer>::BufferWithOwnMemory(unsigned long, char*, unsigned long) build_msan/./src/IO/BufferWithOwnMemory.h:157:29
    #6 0x4843dcec in DB::WriteBufferFromPocoSocket::WriteBufferFromPocoSocket(Poco::Net::Socket&, unsigned long) build_msan/./src/IO/WriteBufferFromPocoSocket.cpp:91:7
    #7 0x483d6d13 in DB::WriteBufferFromPocoSocket* std::__1::construct_at[abi:v15000]<DB::WriteBufferFromPocoSocket, Poco::Net::StreamSocket&, DB::WriteBufferFromPocoSocket*>(DB::WriteBufferFromPocoSocket*, Poco::Net::StreamSocket&) build_msan/./contrib/llvm-project/libcxx/include/__memory/construct_at.h:35:48
    #8 0x483d6d13 in void std::__1::allocator_traits<std::__1::allocator<DB::WriteBufferFromPocoSocket>>::construct[abi:v15000]<DB::WriteBufferFromPocoSocket, Poco::Net::StreamSocket&, void, void>(std::__1::allocator<DB::WriteBufferFromPocoSocket>&, DB::WriteBufferFromPocoSocket*, Poco::Net::StreamSocket&) build_msan/./contrib/llvm-project/libcxx/include/__memory/allocator_traits.h:298:9
    #9 0x483d6d13 in std::__1::__shared_ptr_emplace<DB::WriteBufferFromPocoSocket, std::__1::allocator<DB::WriteBufferFromPocoSocket>>::__shared_ptr_emplace[abi:v15000]<Poco::Net::StreamSocket&>(std::__1::allocator<DB::WriteBufferFromPocoSocket>, Poco::Net::StreamSocket&) build_msan/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:292:9
    #10 0x483d6d13 in std::__1::shared_ptr<DB::WriteBufferFromPocoSocket> std::__1::allocate_shared[abi:v15000]<DB::WriteBufferFromPocoSocket, std::__1::allocator<DB::WriteBufferFromPocoSocket>, Poco::Net::StreamSocket&, void>(std::__1::allocator<DB::WriteBufferFromPocoSocket> const&, Poco::Net::StreamSocket&) build_msan/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:953:55
    #11 0x483d6d13 in std::__1::shared_ptr<DB::WriteBufferFromPocoSocket> std::__1::make_shared[abi:v15000]<DB::WriteBufferFromPocoSocket, Poco::Net::StreamSocket&, void>(Poco::Net::StreamSocket&) build_msan/./contrib/llvm-project/libcxx/include/__memory/shared_ptr.h:962:12
    #12 0x4dbaa65a in DB::TCPHandler::runImpl() build_msan/./src/Server/TCPHandler.cpp:165:11
    #13 0x4dbf6fae in DB::TCPHandler::run() build_msan/./src/Server/TCPHandler.cpp:1999:9
    #14 0x5a92611d in Poco::Net::TCPServerConnection::start() build_msan/./base/poco/Net/src/TCPServerConnection.cpp:43:3
    #15 0x5a9274cf in Poco::Net::TCPServerDispatcher::run() build_msan/./base/poco/Net/src/TCPServerDispatcher.cpp:115:20
    #16 0x5b0bb912 in Poco::PooledThread::run() build_msan/./base/poco/Foundation/src/ThreadPool.cpp:188:14
    #17 0x5b0b6d41 in Poco::(anonymous namespace)::RunnableHolder::run() build_msan/./base/poco/Foundation/src/Thread.cpp:45:11
    #18 0x5b0b2928 in Poco::ThreadImpl::runnableEntry(void*) build_msan/./base/poco/Foundation/src/Thread_POSIX.cpp:335:27
    #19 0x7fb6c70ebbb4 in start_thread /usr/src/debug/glibc/glibc/nptl/pthread_create.c:444:8

SUMMARY: MemorySanitizer: use-of-uninitialized-value build_msan/./base/poco/Net/src/SocketImpl.cpp:290:8 in Poco::Net::SocketImpl::sendBytes(void const*, int, int)
Exiting

Seems like the problem might be introduced with the '\0'.

Metadata

Metadata

Assignees

Labels

majortestingSpecial issue with list of bugs found by CI

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions