From 90aca80865e28a1b9be9bc5ef1118438f62e4f8f Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 17 Mar 2020 14:04:07 +0100 Subject: [PATCH] Fix potential memory corruption when jsV_newmemstring fails to allocate. Don't change the value until the allocation has succeeded. --- jsvalue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsvalue.c b/jsvalue.c index f9c74cc..5537ec6 100644 --- a/jsvalue.c +++ b/jsvalue.c @@ -312,8 +312,8 @@ const char *jsV_tostring(js_State *J, js_Value *v) v->type = JS_TSHRSTR; return v->u.shrstr; } else { - v->type = JS_TMEMSTR; v->u.memstr = jsV_newmemstring(J, p, n); + v->type = JS_TMEMSTR; return v->u.memstr->p; } }