Skip to content

Commit

Permalink
message: verify validity of all header fields
Browse files Browse the repository at this point in the history
Make sure sender, destination, interface, member, and error_name are all
according to the spec.

Signed-off-by: Tom Gundersen <[email protected]>
  • Loading branch information
teg authored and David Herrmann committed Feb 21, 2018
1 parent c354159 commit d1b8143
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/dbus/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,36 +239,48 @@ static int message_parse_header(Message *message, MessageMetadata *metadata) {
if (!strcmp(metadata->fields.interface, "org.freedesktop.DBus.Local"))
return MESSAGE_E_INVALID_HEADER;

/* XXX: invalid interfaces are rejected */
if (!dbus_validate_interface(metadata->fields.interface, strlen(metadata->fields.interface)))
return MESSAGE_E_INVALID_HEADER;

break;

case DBUS_MESSAGE_FIELD_MEMBER:
c_dvar_read(&v, "<s>)", c_dvar_type_s, &metadata->fields.member);

/* XXX: invalid members are rejected */
if (!dbus_validate_member(metadata->fields.member, strlen(metadata->fields.member)))
return MESSAGE_E_INVALID_HEADER;

break;

case DBUS_MESSAGE_FIELD_ERROR_NAME:
c_dvar_read(&v, "<s>)", c_dvar_type_s, &metadata->fields.error_name);
/* XXX: Invalid error-names are rejected */

if (!dbus_validate_error_name(metadata->fields.error_name, strlen(metadata->fields.error_name)))
return MESSAGE_E_INVALID_HEADER;

break;

case DBUS_MESSAGE_FIELD_REPLY_SERIAL:
c_dvar_read(&v, "<u>)", c_dvar_type_u, &metadata->fields.reply_serial);

if (!metadata->fields.reply_serial)
return MESSAGE_E_INVALID_HEADER;

break;

case DBUS_MESSAGE_FIELD_DESTINATION:
c_dvar_read(&v, "<s>)", c_dvar_type_s, &metadata->fields.destination);
/* XXX: Invalid bus-names are rejected */

if (!dbus_validate_name(metadata->fields.destination, strlen(metadata->fields.destination)))
return MESSAGE_E_INVALID_HEADER;

break;

case DBUS_MESSAGE_FIELD_SENDER:
c_dvar_read(&v, "<s>)", c_dvar_type_s, &metadata->fields.sender);
/* XXX: Invalid bus-names are rejected */

if (!dbus_validate_name(metadata->fields.sender, strlen(metadata->fields.sender)))
return MESSAGE_E_INVALID_HEADER;

/* cache sender in case it needs to be stitched out */
message->original_sender = (void *)metadata->fields.sender;
Expand Down

0 comments on commit d1b8143

Please sign in to comment.