[PATCH 1/5] Sanitize attribute handling in policy rule parsing

Pekka Pessi Pekka.Pessi at nokia.com
Fri Jun 4 09:58:42 PDT 2010


Do not allow mixing of send_*, receive_* or user/group/own.
---
 bus/config-parser.c |  133 ++++++++++-----------------------------------------
 1 files changed, 25 insertions(+), 108 deletions(-)

diff --git a/bus/config-parser.c b/bus/config-parser.c
index 2d19f2b..44e9a55 100644
--- a/bus/config-parser.c
+++ b/bus/config-parser.c
@@ -1136,6 +1136,7 @@ append_rule_from_element (BusConfigParser   *parser,
                           dbus_bool_t        allow,
                           DBusError         *error)
 {
+  int send_attr, receive_attr;
   const char *log;
   const char *send_interface;
   const char *send_member;
@@ -1184,12 +1185,13 @@ append_rule_from_element (BusConfigParser   *parser,
                           NULL))
     return FALSE;
 
-  if (!(send_interface || send_member || send_error || send_destination ||
-        send_type || send_path ||
-        receive_interface || receive_member || receive_error || receive_sender ||
-        receive_type || receive_path || eavesdrop ||
-        send_requested_reply || receive_requested_reply ||
-        own || user || group))
+  send_attr = send_interface || send_member || send_error || send_destination ||
+    send_type || send_path || send_requested_reply;
+
+  receive_attr = receive_interface || receive_member || receive_error || receive_sender ||
+    receive_type || receive_path || receive_requested_reply;
+
+  if (!(send_attr || receive_attr || eavesdrop || own || user || group))
     {
       dbus_set_error (error, DBUS_ERROR_FAILED,
                       "Element <%s> must have one or more attributes",
@@ -1205,113 +1207,30 @@ append_rule_from_element (BusConfigParser   *parser,
                       element_name);
       return FALSE;
     }
-  
+
   /* Allowed combinations of elements are:
    *
-   *   base, must be all send or all receive:
+   *   base attributes, must be all send or all receive:
    *     nothing
-   *     interface
-   *     interface + member
-   *     error
-   * 
-   *   base send_ can combine with send_destination, send_path, send_type, send_requested_reply
-   *   base receive_ with receive_sender, receive_path, receive_type, receive_requested_reply, eavesdrop
+   *     *_interface
+   *     *_interface + *_member
+   *     *_path + *_member
+   *     *_error
    *
-   *   user, group, own must occur alone
+   *   base can combine with *_path, *_type, *_requested_reply, eavesdrop
+   *
+   *   base send_ can combine with send_destination
+   *   base receive_  with receive_sender
    *
-   * Pretty sure the below stuff is broken, FIXME think about it more.
+   *   user, group, own must occur alone
    */
 
-  if (((send_interface && send_error) ||
-       (send_interface && receive_interface) ||
-       (send_interface && receive_member) ||
-       (send_interface && receive_error) ||
-       (send_interface && receive_sender) ||
-       (send_interface && receive_requested_reply) ||
-       (send_interface && own) ||
-       (send_interface && user) ||
-       (send_interface && group)) ||
-
-      ((send_member && send_error) ||
-       (send_member && receive_interface) ||
-       (send_member && receive_member) ||
-       (send_member && receive_error) ||
-       (send_member && receive_sender) ||
-       (send_member && receive_requested_reply) ||
-       (send_member && own) ||
-       (send_member && user) ||
-       (send_member && group)) ||
-      
-      ((send_error && receive_interface) ||
-       (send_error && receive_member) ||
-       (send_error && receive_error) ||
-       (send_error && receive_sender) ||
-       (send_error && receive_requested_reply) ||
-       (send_error && own) ||
-       (send_error && user) ||
-       (send_error && group)) ||
-
-      ((send_destination && receive_interface) ||
-       (send_destination && receive_member) ||
-       (send_destination && receive_error) ||
-       (send_destination && receive_sender) ||
-       (send_destination && receive_requested_reply) ||
-       (send_destination && own) ||
-       (send_destination && user) ||
-       (send_destination && group)) ||
-
-      ((send_type && receive_interface) ||
-       (send_type && receive_member) ||
-       (send_type && receive_error) ||
-       (send_type && receive_sender) ||
-       (send_type && receive_requested_reply) ||
-       (send_type && own) ||
-       (send_type && user) ||
-       (send_type && group)) ||
-
-      ((send_path && receive_interface) ||
-       (send_path && receive_member) ||
-       (send_path && receive_error) ||
-       (send_path && receive_sender) ||
-       (send_path && receive_requested_reply) ||
-       (send_path && own) ||
-       (send_path && user) ||
-       (send_path && group)) ||
-
-      ((send_requested_reply && receive_interface) ||
-       (send_requested_reply && receive_member) ||
-       (send_requested_reply && receive_error) ||
-       (send_requested_reply && receive_sender) ||
-       (send_requested_reply && receive_requested_reply) ||
-       (send_requested_reply && own) ||
-       (send_requested_reply && user) ||
-       (send_requested_reply && group)) ||
-      
-      ((receive_interface && receive_error) ||
-       (receive_interface && own) ||
-       (receive_interface && user) ||
-       (receive_interface && group)) ||
-
-      ((receive_member && receive_error) ||
-       (receive_member && own) ||
-       (receive_member && user) ||
-       (receive_member && group)) ||
-      
-      ((receive_error && own) ||
-       (receive_error && user) ||
-       (receive_error && group)) ||
-
-      ((eavesdrop && own) ||
-       (eavesdrop && user) ||
-       (eavesdrop && group)) ||
-
-      ((receive_requested_reply && own) ||
-       (receive_requested_reply && user) ||
-       (receive_requested_reply && group)) ||
-      
+  if ((send_attr && receive_attr) ||
+      ((send_attr || receive_attr || eavesdrop) && (own || user || group)) ||
+      ((send_interface || send_member) && send_error) ||
+      ((receive_interface || receive_member) && receive_error) ||
       ((own && user) ||
        (own && group)) ||
-
       ((user && group)))
     {
       dbus_set_error (error, DBUS_ERROR_FAILED,
@@ -1327,8 +1246,7 @@ append_rule_from_element (BusConfigParser   *parser,
    */
 #define IS_WILDCARD(str) ((str) && ((str)[0]) == '*' && ((str)[1]) == '\0')
 
-  if (send_interface || send_member || send_error || send_destination ||
-      send_path || send_type || send_requested_reply)
+  if (send_attr)
     {
       int message_type;
       
@@ -1408,8 +1326,7 @@ append_rule_from_element (BusConfigParser   *parser,
       if (send_destination && rule->d.send.destination == NULL)
         goto nomem;
     }
-  else if (receive_interface || receive_member || receive_error || receive_sender ||
-           receive_path || receive_type || eavesdrop || receive_requested_reply)
+  else if (receive_attr || eavesdrop)
     {
       int message_type;
       
-- 
1.6.3.3



More information about the dbus mailing list