Mercurial Hosting > luan
diff src/luan/LuanTable.java @ 1330:f41919741100
fix security
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 11 Feb 2019 01:38:55 -0700 |
parents | 1b46c8e6c647 |
children | 25746915a241 |
line wrap: on
line diff
--- a/src/luan/LuanTable.java Sun Feb 10 02:01:49 2019 -0700 +++ b/src/luan/LuanTable.java Mon Feb 11 01:38:55 2019 -0700 @@ -18,19 +18,20 @@ private Map map = null; private List list = null; private LuanTable metatable = null; - public LuanJavaOk javaOk; + public LuanClosure closure; private LuanCloner cloner; + private String security = null; public LuanTable(LuanState luan) { this.luan = luan; } - public LuanTable(LuanState luan,List list) { + public LuanTable(LuanState luan,List list){ int n = list.size(); for( int i=0; i<n; i++ ) { Object val = list.get(i); if( val != null ) - rawPut(i+1,val); + rawPut2(i+1,val); } } @@ -41,15 +42,15 @@ Object key = entry.getKey(); Object value = entry.getValue(); if( key != null && value != null ) - rawPut(key,value); + rawPut2(key,value); } } - public LuanTable(LuanState luan,Set set) { + public LuanTable(LuanState luan,Set set){ this.luan = luan; for( Object el : set ) { if( el != null ) - rawPut(el,Boolean.TRUE); + rawPut2(el,Boolean.TRUE); } } @@ -69,6 +70,7 @@ @Override public void deepenClone(LuanCloneable dc,LuanCloner cloner) { check(); LuanTable clone = (LuanTable)dc; + clone.security = security; switch( cloner.type ) { case COMPLETE: deepenClone(clone,cloner); @@ -78,7 +80,7 @@ clone.map = map; clone.list = list; clone.metatable = metatable; - clone.javaOk = javaOk; + clone.closure = closure; return; } } @@ -108,7 +110,7 @@ clone.list = newList; } clone.metatable = (LuanTable)cloner.clone(metatable); - clone.javaOk = (LuanJavaOk)cloner.clone(javaOk); + clone.closure = (LuanClosure)cloner.clone(closure); } public boolean isList() { @@ -189,7 +191,13 @@ throw new LuanException("invalid type "+Luan.type(h)+" for metamethod __new_index"); } - public void rawPut(Object key,Object val) { + public void rawPut(Object key,Object val) throws LuanException { + if( security != null ) + Luan.checkSecurity(luan,"table",security,"put",key,val); + rawPut2(key,val); + } + + private void rawPut2(Object key,Object val) { check(); Integer iT = Luan.asInteger(key); if( iT != null ) { @@ -437,7 +445,9 @@ return metatable; } - public void setMetatable(LuanTable metatable) { + public void setMetatable(LuanTable metatable) throws LuanException { + if( security != null ) + Luan.checkSecurity(luan,"table",security,"set_metatable",metatable); check(); this.metatable = metatable; } @@ -516,4 +526,8 @@ LuanFunction fn = (LuanFunction)get(fnName); return fn.call(luan,args); } + + public static void setSecurity(LuanTable tbl,String security) { + tbl.security = security; + } }