forked from Kistler-Group/sdbus-cpp
Fix issue #135: Segfault in Message::peekType()
* Add missing nullptr check in Message::peekType(). * According to its specification, sd_bus_message_peek_type() sets a given contents parameter to NULL if the next element in a message is not a container. Since assigning a nullptr to a std::string has undefined behaviour (typically resulting in an invalid memory access), Message::peekType() must not assign contentsSig unconditionally.
This commit is contained in:
committed by
Stanislav Angelovič
parent
fa9569fdd9
commit
a5e94f07bf
+1
-1
@@ -617,7 +617,7 @@ void Message::peekType(std::string& type, std::string& contents) const
|
||||
auto r = sd_bus_message_peek_type((sd_bus_message*)msg_, &typeSig, &contentsSig);
|
||||
SDBUS_THROW_ERROR_IF(r < 0, "Failed to peek message type", -r);
|
||||
type = typeSig;
|
||||
contents = contentsSig;
|
||||
contents = contentsSig ? contentsSig : "";
|
||||
}
|
||||
|
||||
bool Message::isValid() const
|
||||
|
||||
Reference in New Issue
Block a user