commit bfb6c26

default  ·  2024-10-19 16:29:58 +0000 UTC
parent cb3bb90
Added some checks.
1 files changed,  +42, -10
+42, -10
  1@@ -1772,7 +1772,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
  2         if (xs_type(obj_id) == XSTYPE_DICT)
  3             obj_id = xs_dict_get(obj_id, "id");
  4 
  5-        if (!object_here(obj_id)) {
  6+        if (xs_is_null(obj_id) || !object_here(obj_id)) {
  7             srv_debug(1, xs_fmt("dropped 'Delete' message from unknown object '%s'", obj_id));
  8             return -1;
  9         }
 10@@ -1871,6 +1871,12 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
 11     }
 12 
 13     if (strcmp(type, "Follow") == 0) { /** **/
 14+        const char *id = xs_dict_get(msg, "id");
 15+
 16+        if (xs_is_null(id)) {
 17+            snac_log(snac, xs_fmt("malformed message: no 'id' field"));
 18+        }
 19+        else
 20         if (!follower_check(snac, actor)) {
 21             /* ensure the actor object is here */
 22             if (!object_here(actor)) {
 23@@ -1890,7 +1896,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
 24                 f_msg = xs_dict_set(f_msg, "published", date);
 25             }
 26 
 27-            timeline_add(snac, xs_dict_get(f_msg, "id"), f_msg);
 28+            timeline_add(snac, id, f_msg);
 29 
 30             follower_add(snac, actor);
 31 
 32@@ -1988,6 +1994,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
 33         if (strcmp(utype, "Question") == 0) { /**  **/
 34             const char *id = xs_dict_get(object, "id");
 35 
 36+            if (xs_is_null(id))
 37+                snac_log(snac, xs_fmt("malformed message: no 'id' field"));
 38+            else
 39             if (timeline_add(snac, id, object))
 40                 snac_log(snac, xs_fmt("new 'Question' %s %s", actor, id));
 41         }
 42@@ -1995,6 +2004,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
 43         if (strcmp(utype, "Video") == 0) { /** **/
 44             const char *id = xs_dict_get(object, "id");
 45 
 46+            if (xs_is_null(id))
 47+                snac_log(snac, xs_fmt("malformed message: no 'id' field"));
 48+            else
 49             if (timeline_add(snac, id, object))
 50                 snac_log(snac, xs_fmt("new 'Video' %s %s", actor, id));
 51         }
 52@@ -2037,10 +2049,13 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
 53         if (xs_type(object) == XSTYPE_DICT)
 54             object = xs_dict_get(object, "id");
 55 
 56+        if (xs_is_null(object))
 57+            snac_log(snac, xs_fmt("malformed message: no 'id' field"));
 58+        else
 59         if (timeline_admire(snac, object, actor, 1) == HTTP_STATUS_CREATED)
 60             snac_log(snac, xs_fmt("new '%s' %s %s", type, actor, object));
 61         else
 62-            snac_log(snac, xs_fmt("repeated 'Like' from %s to %s", actor, object));
 63+            snac_log(snac, xs_fmt("repeated '%s' from %s to %s", type, actor, object));
 64 
 65         do_notify = 1;
 66     }
 67@@ -2049,6 +2064,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
 68         if (xs_type(object) == XSTYPE_DICT)
 69             object = xs_dict_get(object, "id");
 70 
 71+        if (xs_is_null(object))
 72+            snac_log(snac, xs_fmt("malformed message: no 'id' field"));
 73+        else
 74         if (is_muted(snac, actor) && !xs_startswith(object, snac->actor))
 75             snac_log(snac, xs_fmt("dropped 'Announce' from muted actor %s", actor));
 76         else
 77@@ -2101,6 +2119,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
 78         if (xs_match(utype, "Note|Page|Article|Video")) { /** **/
 79             const char *id = xs_dict_get(object, "id");
 80 
 81+            if (xs_is_null(id))
 82+                snac_log(snac, xs_fmt("malformed message: no 'id' field"));
 83+            else
 84             if (object_here(id)) {
 85                 object_add_ow(id, object);
 86                 timeline_touch(snac);
 87@@ -2115,13 +2136,17 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
 88             const char *id     = xs_dict_get(object, "id");
 89             const char *closed = xs_dict_get(object, "closed");
 90 
 91-            object_add_ow(id, object);
 92-            timeline_touch(snac);
 93+            if (xs_is_null(id))
 94+                snac_log(snac, xs_fmt("malformed message: no 'id' field"));
 95+            else {
 96+                object_add_ow(id, object);
 97+                timeline_touch(snac);
 98 
 99-            snac_log(snac, xs_fmt("%s poll %s", closed == NULL ? "updated" : "closed", id));
100+                snac_log(snac, xs_fmt("%s poll %s", closed == NULL ? "updated" : "closed", id));
101 
102-            if (closed != NULL)
103-                do_notify = 1;
104+                if (closed != NULL)
105+                    do_notify = 1;
106+            }
107         }
108         else {
109             srv_archive_error("unsupported_update", "unsupported_update", req, msg);
110@@ -2134,6 +2159,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
111         if (xs_type(object) == XSTYPE_DICT)
112             object = xs_dict_get(object, "id");
113 
114+        if (xs_is_null(object))
115+            snac_log(snac, xs_fmt("malformed message: no 'id' field"));
116+        else
117         if (object_here(object)) {
118             timeline_del(snac, object);
119             snac_debug(snac, 1, xs_fmt("new 'Delete' %s %s", actor, object));
120@@ -2147,11 +2175,15 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
121     }
122     else
123     if (strcmp(type, "Ping") == 0) { /** **/
124+        const char *id = xs_dict_get(msg, "id");
125+
126         snac_log(snac, xs_fmt("'Ping' requested from %s", actor));
127 
128-        xs *rsp = msg_pong(snac, actor, xs_dict_get(msg, "id"));
129+        if (!xs_is_null(id)) {
130+            xs *rsp = msg_pong(snac, actor, id);
131 
132-        enqueue_output_by_actor(snac, rsp, actor, 0);
133+            enqueue_output_by_actor(snac, rsp, actor, 0);
134+        }
135     }
136     else
137     if (strcmp(type, "Block") == 0) { /** **/