[Converter/subplugins] Fix use after free
authorGichan Jang <gichan2.jang@samsung.com>
Tue, 25 May 2021 10:11:00 +0000 (19:11 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 26 May 2021 13:09:55 +0000 (22:09 +0900)
The internal representation of temporary of type std::string is freed by its destructor.
Copy the std::string to avoid use after free.

Signed-off-by: Gichan Jang <gichan2.jang@samsung.com>
ext/nnstreamer/extra/nnstreamer_protobuf.cc
ext/nnstreamer/tensor_converter/tensor_converter_flatbuf.cc
ext/nnstreamer/tensor_converter/tensor_converter_flexbuf.cc

index 0beac5e..c712764 100644 (file)
@@ -149,7 +149,8 @@ gst_tensor_converter_protobuf (GstBuffer *in_buf, GstTensorsConfig *config, void
 
   for (guint i = 0; i < config->info.num_tensors; i++) {
     const nnstreamer::protobuf::Tensor *tensor = &tensors.tensor (i);
-    const gchar *name = tensor->name ().c_str ();
+    std::string _name = tensor->name ();
+    const gchar *name = _name.c_str ();
 
     config->info.info[i].name = (name && strlen (name) > 0) ? g_strdup (name) : NULL;
     config->info.info[i].type = (tensor_type)tensor->type ();
index a3f1c6b..b01f668 100644 (file)
@@ -128,7 +128,8 @@ fbc_convert (GstBuffer *in_buf, GstTensorsConfig *config, void *priv_data)
 
   for (guint i = 0; i < config->info.num_tensors; i++) {
     gsize offset;
-    const gchar *name = tensor->Get (i)->name ()->str ().c_str ();
+    std::string _name = tensor->Get (i)->name ()->str ();
+    const gchar *name = _name.c_str ();
 
     config->info.info[i].name = (name && strlen (name) > 0) ? g_strdup (name) : NULL;
     config->info.info[i].type = (tensor_type)tensor->Get (i)->type ();
index d85e8f6..180c486 100644 (file)
@@ -145,7 +145,8 @@ flxc_convert (GstBuffer *in_buf, GstTensorsConfig *config, void *priv_data)
     gchar * tensor_key = g_strdup_printf ("tensor_%d", i);
     gsize offset;
     flexbuffers::Vector tensor = tensors[tensor_key].AsVector ();
-    const gchar *name = tensor[0].AsString ().c_str ();
+    flexbuffers::String _name = tensor[0].AsString ();
+    const gchar *name = _name.c_str ();
 
     config->info.info[i].name = (name && strlen (name) > 0) ? g_strdup (name) : NULL;
     config->info.info[i].type = (tensor_type) tensor[1].AsInt32 ();