Skip to content

Commit 2658e53

Browse files
committed
Add validation for GlobalSection
* The type of the value returned by init must be the same as desc's type.
1 parent 7e36eff commit 2658e53

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

TBInit.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ def TypeSection(self):
193193

194194
def ImportSection(self):
195195
section = self.module.import_section
196+
if section is None:
197+
return(True)
196198
for entry in section.import_entry:
197199
if entry.kind == External_Kind.FUNCTION:
198200
pass
@@ -223,10 +225,37 @@ def MemorySection(self):
223225
pass
224226

225227
def GlobalSection(self):
226-
pass
228+
section = self.module.global_section
229+
if section is None:
230+
return(True)
231+
for entry in section.global_variables:
232+
desc_type = entry.global_type.content_type
233+
init_expr = entry.init_expr
234+
#get_global
235+
if init_expr[0] == 0x23:
236+
index = init_expr[1]
237+
glob = self.module.global_index_space[index]
238+
if desc_type != glob.content_type:
239+
return(False)
240+
#const
241+
elif init_expr[0] == 0x41:
242+
if desc_type != 0x7f:
243+
return(False)
244+
elif init_expr[0] == 0x42:
245+
if desc_type != 0x7e:
246+
return(False)
247+
elif init_expr[0] == 0x43:
248+
if desc_type != 0x7d:
249+
return(False)
250+
elif init_expr[0] == 0x44:
251+
if desc_type != 0x7c:
252+
return(False)
253+
return(True)
227254

228255
def ExportSection(self):
229256
section = self.module.export_section
257+
if section is None:
258+
return(True)
230259
name_list = {}
231260
for entry in section.export_entries:
232261
name = ''.join(chr(c) for c in entry.field_str)

argparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ def ReadExportSection(self):
814814

815815
for i in range(0, field_length):
816816
field_name.append(export_section[6][offset + i])
817-
temp_export_entry.fiels_str = field_name
817+
temp_export_entry.field_str = field_name
818818
offset += field_length
819819

820820
kind, offset, dummy = Read(export_section[6], offset, 'uint8')

0 commit comments

Comments
 (0)