[gjs/gnome-3-34] arg: Avoid data corruption when marshalling unsupported flat array



commit 864223b02bda394c94671c60a48d5e1b6fee3465
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 1b2be888..3e6aae5c 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1121,6 +1121,21 @@ gjs_array_to_array(JSContext   *context,
 
     /* 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]