davidm / luacom

Microsoft Component Object Model (COM) binding for Lua
http://lua-users.org/wiki/LuaCom
Other
116 stars 51 forks source link

Build saferarray as 0-based #16

Open moteus opened 7 years ago

moteus commented 7 years ago

https://github.com/moteus/luacom/commit/0542f4b519fbba8b5469b7201e1a62aa11c7fa9e I found problem with some Microsoft interfaces wich crashes when you try send 1-based arrays. And because VBS uses 0-based arrays I think it should be safer use it. Test example crash with Access violation.

local luacom = require "luacom"

local FwPolicy2PROGID = "HNetCfg.FwPolicy2"
local FwPolicy2CLSID  = luacom.CLSIDfromProgID(FwPolicy2PROGID)

local policy = luacom.CreateObject(FwPolicy2CLSID)

-- Important that profile had interfaces
policy:getExcludedInterfaces(2)
policy:setExcludedInterfaces(2, {'{01C221C0-0000-0000-2E7E-974EF0F8D046}'})

Tracestack is

kernel32.dll!_LongCompareString@4()
kernel32.dll!_SortCompareString@32()
KernelBase.dll!_SortCompareString@36()
KernelBase.dll!_CompareStringW@24()
FirewallAPI.dll!FwInterfaceNameToLuid(struct _IP_ADAPTER_ADDRESSES_LH *,unsigned short * const,struct _GUID *)
FirewallAPI.dll!FwSafearrayToLuids(struct tagVARIANT,struct _tag_FW_INTERFACE_LUIDS *)
FirewallAPI.dll!FwPolicy2::put_ExcludedInterfaces(enum NET_FW_PROFILE_TYPE2_,struct tagVARIANT)
oleaut32.dll!_DispCallFunc@32()
oleaut32.dll!CTypeInfo2::Invoke(void *,long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)
FirewallAPI.dll!ATL::IDispatchImpl<struct INetFwPolicy2,&struct __s_GUID const _GUID_98325047_c671_4174_8d81_defcd3f03186,&struct _GUID const LIBID_NetFwTypeLib,1,0,class ATL::CComTypeInfoHolder>::Invoke(long,struct _GUID const &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)
luacom.dll!tLuaCOM::call(lua_State * L, long dispid, int invkind, tagFUNCDESC * pfuncdesc, tLuaObjList params)

This example does not crash

Set fwPolicy2 = CreateObject("HNetCfg.FwPolicy2")
InterfaceArray = fwPolicy2.ExcludedInterfaces(2)
fwPolicy2.ExcludedInterfaces(2) = Array("{01C5E0B0-0000-0000-2E7E-974EF0F8D046}")