From f055a9dffd9ba403a99266a662b9992bc89dcaa1 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Sun, 25 Feb 2018 09:43:52 -0300 Subject: [PATCH] added check in 'obj2gco' to prevent its use in non Lua-object pointers (otherwise its cast is blind, casting any value given to it) --- lstate.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lstate.h b/lstate.h index 06581b01..974249de 100644 --- a/lstate.h +++ b/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.155 2018/02/15 18:06:24 roberto Exp roberto $ +** $Id: lstate.h,v 2.156 2018/02/17 19:29:29 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -252,8 +252,11 @@ union GCUnion { #define gco2upv(o) check_exp((o)->tt == LUA_TUPVAL, &((cast_u(o))->upv)) -/* macro to convert a Lua object into a GCObject */ -#define obj2gco(v) (&(cast_u(v)->gc)) +/* +** macro to convert a Lua object into a GCObject +** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.) +*/ +#define obj2gco(v) check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc)) /* actual number of total bytes allocated */