Skip to content

Commit f7dd5a0

Browse files
committed
Simple buffer overflow detection on glGet*.
1 parent 0e3c21c commit f7dd5a0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

glstate.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ def visit_array(self, array, args):
154154
elem_type = self.inflector.reduced_type(array.type)
155155
inflection = self.inflector.inflect(array.type)
156156
assert inflection.endswith('v')
157-
print ' %s %s[%s];' % (elem_type, temp_name, array.length)
157+
print ' %s %s[%s + 1];' % (elem_type, temp_name, array.length)
158158
print ' memset(%s, 0, %s * sizeof *%s);' % (temp_name, array.length, temp_name)
159+
print ' %s[%s] = (%s)0xdeadc0de;' % (temp_name, array.length, elem_type)
159160
print ' %s(%s, %s);' % (inflection + self.suffix, ', '.join(args), temp_name)
161+
# Simple buffer overflow detection
162+
print ' assert(%s[%s] == (%s)0xdeadc0de);' % (temp_name, array.length, elem_type)
160163
return temp_name
161164

162165
def visit_opaque(self, pointer, args):

0 commit comments

Comments
 (0)