mesh: Add validation of Device UUID value
authorInga Stotland <inga.stotland@intel.com>
Fri, 12 Feb 2021 21:42:42 +0000 (13:42 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:34 +0000 (19:08 +0530)
Validate that the value of Device UUID supplied in
CreateNetwork/Join/Import methods is compliant with RFC 4122.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
Makefile.am
mesh/mesh.c

index 99fd81e..9b78d12 100755 (executable)
@@ -135,7 +135,8 @@ ell_headers = ell/util.h \
                         ell/base64.h \
                         ell/asn1-private.h \
                         ell/cert-private.h \
-                        ell/pem-private.h
+                        ell/pem-private.h \
+                       ell/uuid.h
 
 ell_sources = ell/private.h ell/missing.h \
                         ell/util.c \
@@ -170,7 +171,8 @@ ell_sources = ell/private.h ell/missing.h \
                         ell/gvariant-private.h \
                         ell/gvariant-util.c \
                         ell/siphash-private.h \
-                        ell/siphash.c
+                        ell/siphash.c \
+                       ell/uuid.c
 
 ell_libell_internal_la_SOURCES = $(ell_headers) $(ell_sources)
 endif
index 890855a..b377010 100644 (file)
@@ -532,7 +532,7 @@ static struct l_dbus_message *join_network_call(struct l_dbus *dbus,
                                                void *user_data)
 {
        const char *app_path, *sender;
-       struct l_dbus_message_iter iter_uuid;
+       struct l_dbus_message_iter iter;
        uint32_t n;
 
        l_debug("Join network request");
@@ -542,14 +542,13 @@ static struct l_dbus_message *join_network_call(struct l_dbus *dbus,
                                                "Provisioning in progress");
 
        if (!l_dbus_message_get_arguments(msg, "oay", &app_path,
-                                                               &iter_uuid))
+                                                               &iter))
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
 
        join_pending = l_new(struct join_data, 1);
 
-       if (!l_dbus_message_iter_get_fixed_array(&iter_uuid,
-                                               &join_pending->uuid, &n)
-                                                               || n != 16) {
+       if (!l_dbus_message_iter_get_fixed_array(&iter, &join_pending->uuid, &n)
+                       || n != 16 || !l_uuid_is_valid(join_pending->uuid)) {
                l_free(join_pending);
                join_pending = NULL;
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
@@ -807,8 +806,8 @@ static struct l_dbus_message *create_network_call(struct l_dbus *dbus,
                                                                &iter_uuid))
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
 
-       if (!l_dbus_message_iter_get_fixed_array(&iter_uuid, &uuid, &n)
-                                                               || n != 16)
+       if (!l_dbus_message_iter_get_fixed_array(&iter_uuid, &uuid, &n) ||
+                                       n != 16 || !l_uuid_is_valid(uuid))
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
                                                        "Bad device UUID");
 
@@ -857,8 +856,9 @@ static struct l_dbus_message *import_call(struct l_dbus *dbus,
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
 
        if (!l_dbus_message_iter_get_fixed_array(&iter_uuid, &uuid, &n) ||
-                                                                       n != 16)
-               return dbus_error(msg, MESH_ERROR_INVALID_ARGS, "Bad dev UUID");
+                                       n != 16 || !l_uuid_is_valid(uuid))
+               return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
+                                                       "Bad device UUID");
 
        if (node_find_by_uuid(uuid))
                return dbus_error(msg, MESH_ERROR_ALREADY_EXISTS,