@@ -1883,6 +1883,9 @@ func writeWasmtimeLambda(w LanguageWriter, NameSpace string, method ComponentDef
1883
1883
if ! cParamIsPointer (cParam ) {
1884
1884
pointerString = "*"
1885
1885
}
1886
+ // ensure memory access does not go outside of WASM linear memory
1887
+ lines = append (lines , fmt .Sprintf ("if (w%s + sizeof(%s) >= nMemorySize)" , cParam .ParamName , cParam .ParamType ))
1888
+ lines = append (lines , fmt .Sprintf (" return %s_ERROR_INVALIDPARAM;" , strings .ToUpper (NameSpace )))
1886
1889
lines = append (lines , fmt .Sprintf ("%s %s = %s( (%s %s)(_pData + w%s) );" , cParam .ParamType , cParam .ParamName , pointerString , cParam .ParamType , pointerString , cParam .ParamName ))
1887
1890
if cParamIsPointer (cParam ) {
1888
1891
// a nullptr in the WASM module is conveyed to the host as a 0 offset in WASM linear memory
@@ -1895,9 +1898,9 @@ func writeWasmtimeLambda(w LanguageWriter, NameSpace string, method ComponentDef
1895
1898
1896
1899
w .Writeln (" auto %s = [this, &store](%s)" , methodName , wasmtimeParams )
1897
1900
w .Writeln (" {" )
1898
- w .Writeln (" " )
1899
1901
w .Writeln (" auto data = this->m_pMemory->data(store);" )
1900
1902
w .Writeln (" uint8_t* _pData = data.data();" )
1903
+ w .Writeln (" const uint64_t nMemorySize = this->m_pMemory->size(store);" )
1901
1904
w .Writeln (" " )
1902
1905
1903
1906
w .Writelns (" " , lines )
@@ -1943,7 +1946,7 @@ func buildCppwasmHostHeader(component ComponentDefinition, w LanguageWriter, Nam
1943
1946
}
1944
1947
w .Writeln ("" )
1945
1948
1946
- w .Writeln ("namespace %s {" , NameSpace )
1949
+ w .Writeln ("namespace %sWASM {" , NameSpace )
1947
1950
w .Writeln ("" )
1948
1951
1949
1952
w .Writeln ("/*************************************************************************************************************************" )
0 commit comments