Jacek Caban : vbscript: Alloc vbscode_t before parsing the script.
Alexandre Julliard
julliard at winehq.org
Thu Jan 23 15:48:48 CST 2020
Module: wine
Branch: master
Commit: 70cd4153c558fbfba9ddb86a591872ce55d4184e
URL: https://source.winehq.org/git/wine.git/?a=commit;h=70cd4153c558fbfba9ddb86a591872ce55d4184e
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Jan 22 23:27:09 2020 +0100
vbscript: Alloc vbscode_t before parsing the script.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/vbscript/compile.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c
index c76ba73bd8..4a1f1a5c6a 100644
--- a/dlls/vbscript/compile.c
+++ b/dlls/vbscript/compile.c
@@ -1851,16 +1851,24 @@ void release_vbscode(vbscode_t *code)
static vbscode_t *alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source)
{
vbscode_t *ret;
+ size_t len;
+
+ len = source ? lstrlenW(source) : 0;
+ if(len > INT32_MAX)
+ return NULL;
ret = heap_alloc_zero(sizeof(*ret));
if(!ret)
return NULL;
- ret->source = heap_strdupW(source);
+ ret->source = heap_alloc((len + 1) * sizeof(WCHAR));
if(!ret->source) {
heap_free(ret);
return NULL;
}
+ if(len)
+ memcpy(ret->source, source, len * sizeof(WCHAR));
+ ret->source[len] = 0;
ret->instrs = heap_alloc(32*sizeof(instr_t));
if(!ret->instrs) {
@@ -1872,8 +1880,6 @@ static vbscode_t *alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source)
ctx->instr_size = 32;
heap_pool_init(&ret->heap);
- ret->option_explicit = ctx->parser.option_explicit;
-
ret->main_code.type = FUNC_GLOBAL;
ret->main_code.code_ctx = ret;
ret->ref = 1;
@@ -1899,15 +1905,16 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli
vbscode_t *code;
HRESULT hres;
- if (!src) src = L"";
-
- hres = parse_script(&ctx.parser, src, delimiter, flags);
- if(FAILED(hres))
- return compile_error(script, hres);
-
code = ctx.code = alloc_vbscode(&ctx, src);
if(!ctx.code)
- return compile_error(script, E_OUTOFMEMORY);
+ return E_OUTOFMEMORY;
+
+ hres = parse_script(&ctx.parser, code->source, delimiter, flags);
+ if(FAILED(hres)) {
+ hres = compile_error(script, hres);
+ release_vbscode(code);
+ return hres;
+ }
ctx.func_decls = NULL;
ctx.labels = NULL;
@@ -1922,6 +1929,8 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli
}
ctx.global_consts = ctx.const_decls;
+ code->option_explicit = ctx.parser.option_explicit;
+
for(func_decl = ctx.func_decls; func_decl; func_decl = func_decl->next) {
hres = create_function(&ctx, func_decl, &new_func);
More information about the wine-cvs
mailing list