[gjs: 1/3] arg: Avoid data corruption when marshalling unsupported flat array



commit 5cb34600b13cfdbf101823a8636dc6469103e510
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Oct 26 14:21:47 2019 -0700

    arg: Avoid data corruption when marshalling unsupported flat array
    
    Currently, when a function is supposed to receive a flat array (for
    example, regress_test_array_struct_in_full() taking RegressTestStructA*)
    GJS will instead construct a pointer array (RegressTestStructA** in the
    above example) and try to pass it to the function. This leads to garbage
    data being passed to the function and possibly crashes.
    
    Anticipate this situation and throw an exception instead.
    
    Related to #44.

 gi/arg.cpp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 3d47cc54..d5539d52 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1116,6 +1116,21 @@ static bool gjs_array_to_array(JSContext* context, JS::HandleValue array_value,
 
     /* Everything else is a pointer type */
     case GI_TYPE_TAG_INTERFACE:
+        // Flat arrays of structures are not supported yet; see
+        // https://gitlab.gnome.org/GNOME/gjs/issues/44
+        if (!g_type_info_is_pointer(param_info)) {
+            GjsAutoBaseInfo interface_info =
+                g_type_info_get_interface(param_info);
+            GIInfoType info_type = g_base_info_get_type(interface_info);
+            if (info_type == GI_INFO_TYPE_STRUCT ||
+                info_type == GI_INFO_TYPE_UNION) {
+                gjs_throw(context,
+                      "Flat array of type %s is not currently supported",
+                      interface_info.name());
+                return false;
+            }
+        }
+        /* fall through */
     case GI_TYPE_TAG_ARRAY:
     case GI_TYPE_TAG_GLIST:
     case GI_TYPE_TAG_GSLIST:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]