[Git][gajim/gajim][master] 2 commits: Detect invalid user mood

Philipp Hörist gitlab at dev.gajim.org
Sat Jan 19 21:29:28 CET 2019


Philipp Hörist pushed to branch master at gajim / gajim


Commits:
7c7df9d4 by Philipp Hörist at 2019-01-19T20:21:16Z
Detect invalid user mood

Fixes #9546, #9547

- - - - -
3e362874 by Philipp Hörist at 2019-01-19T20:21:20Z
Detect invalid user activity

- - - - -


2 changed files:

- gajim/common/modules/user_activity.py
- gajim/common/modules/user_mood.py


Changes:

=====================================
gajim/common/modules/user_activity.py
=====================================
@@ -65,6 +65,9 @@ class UserActivity(AbstractPEPModule):
         if activity_tag is None:
             raise StanzaMalformed('No activity node')
 
+        if not activity_tag.getChildren():
+            return None
+
         for child in activity_tag.getChildren():
             name = child.getName().strip()
             data = child.getData().strip()
@@ -76,17 +79,22 @@ class UserActivity(AbstractPEPModule):
                     subactivity_name = subactivity.getName().strip()
                     activity_dict['subactivity'] = subactivity_name
 
-        return activity_dict or None
+        if 'activity' not in activity_dict:
+            raise StanzaMalformed('No activity value found')
+        return activity_dict
 
     def _build_node(self, data):
         item = nbxmpp.Node('activity', {'xmlns': self.namespace})
         if data is None:
             return item
+
         activity, subactivity, message = data
-        if activity:
-            i = item.addChild(activity)
-            if subactivity:
-                i.addChild(subactivity)
+        if not activity:
+            return item
+
+        i = item.addChild(activity)
+        if subactivity:
+            i.addChild(subactivity)
         if message:
             i = item.addChild('text')
             i.addData(message)


=====================================
gajim/common/modules/user_mood.py
=====================================
@@ -67,6 +67,9 @@ class UserMood(AbstractPEPModule):
         if mood_tag is None:
             raise StanzaMalformed('No mood node')
 
+        if not mood_tag.getChildren():
+            return None
+
         for child in mood_tag.getChildren():
             name = child.getName().strip()
             if name == 'text':
@@ -74,15 +77,20 @@ class UserMood(AbstractPEPModule):
             else:
                 mood_dict['mood'] = name
 
-        return mood_dict or None
+        if 'mood' not in mood_dict:
+            raise StanzaMalformed('No mood value found')
+        return mood_dict
 
     def _build_node(self, data: Optional[Tuple[str, str]]) -> nbxmpp.Node:
         item = nbxmpp.Node('mood', {'xmlns': nbxmpp.NS_MOOD})
         if data is None:
             return item
+
         mood, text = data
-        if mood:
-            item.addChild(mood)
+        if not mood:
+            return item
+        item.addChild(mood)
+
         if text:
             item.addChild('text', payload=text)
         return item



View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/cf8eafffb28fa4acb48e4eda44be35b7db475d77...3e362874be08c14aa643e042d0e7e2e899a58741

-- 
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/cf8eafffb28fa4acb48e4eda44be35b7db475d77...3e362874be08c14aa643e042d0e7e2e899a58741
You're receiving this email because of your account on dev.gajim.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gajim.org/pipermail/commits/attachments/20190119/e03341ed/attachment-0001.html>


More information about the Commits mailing list