srt icon indicating copy to clipboard operation
srt copied to clipboard

[BUG] Static Sanitizer Error

Open jlsantiago0 opened this issue 2 years ago • 3 comments

Testing with Master, reported by Static Sanitizer GCC-12.1.0.

In ‘srt::CPacket::CPacket()’: constructor. value in m_nHeader[SRT_PH_SEQNO] is referenced before it is set.

/mnt/share/open/toolchain/gcc12/tesu/ub16-32/srt/srtcore/packet.cpp: In constructor ‘srt::CPacket::CPacket()’:
/mnt/share/open/toolchain/gcc12/tesu/ub16-32/srt/srtcore/packet.cpp:180:25: warning: member ‘srt::CPacket::m_nHeader’ is used uninitialized [-Wuninitialized]
  180 |     m_iSeqNo((int32_t&)(m_nHeader[SRT_PH_SEQNO])),

jlsantiago0 avatar Jun 28 '22 21:06 jlsantiago0

I think a constructor added to DynamicStruct with a parameter (so that it doesn't cover the default constructor) could be called before these fields and that would clear it earlier than the reference initialization, but I don't know if it's worth a shot.

ethouris avatar Jun 29 '22 07:06 ethouris

Perhaps it can read it inside the body of the constructor after m_nHeader.clear() is called (assuming that initializes the memory). Probably not a huge deal, although reading from uninitialized memory is undefined behavior, even if you later dont use the value read from it.

What can happen for instance if this field happens to be in a page frame that has not been mapped by the OS yet (Linux does it lazily and some other OSes as well) which can happen if it hasn't been written to, then the read from it could cause a segfault, even if it is in the memory range of the object. Might not happen very often of very likely, but can happen.

jlsantiago0 avatar Jun 29 '22 13:06 jlsantiago0

Hmm, then it may be worth a shot.

ethouris avatar Jun 29 '22 14:06 ethouris