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:
Benjamin Kaufmann
2021-06-15 15:26:10 +02:00
committed by Stanislav Angelovič
parent fa9569fdd9
commit a5e94f07bf
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -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