[PATCH v4 03/10] vbscript: Copy the variable names into the script dispatch's heap.

Gabriel Ivăncescu gabrielopcode at gmail.com
Mon Nov 25 08:09:35 CST 2019


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/vbscript/vbscript.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c
index 94daace..6c30869 100644
--- a/dlls/vbscript/vbscript.c
+++ b/dlls/vbscript/vbscript.c
@@ -63,6 +63,15 @@ typedef struct {
     EXCEPINFO ei;
 } VBScriptError;
 
+static inline WCHAR *strcpy_to_heap_pool(heap_pool_t *heap, const WCHAR *str)
+{
+    size_t size = (lstrlenW(str) + 1) * sizeof(WCHAR);
+    WCHAR *ret = heap_pool_alloc(heap, size);
+
+    if (ret) memcpy(ret, str, size);
+    return ret;
+}
+
 static void change_state(VBScript *This, SCRIPTSTATE state)
 {
     if(This->state == state)
@@ -120,7 +129,9 @@ static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res
         if (!(var = heap_pool_alloc(&obj->heap, sizeof(*var))))
             return E_OUTOFMEMORY;
 
-        var->name = code->main_code.vars[i].name;
+        var->name = strcpy_to_heap_pool(&obj->heap, code->main_code.vars[i].name);
+        if (!var->name)
+            return E_OUTOFMEMORY;
         V_VT(&var->v) = VT_EMPTY;
         var->is_const = FALSE;
         var->array = NULL;
-- 
2.21.0




More information about the wine-devel mailing list