]> git.cworth.org Git - apitrace/commitdiff
Simple buffer overflow detection on glGet*.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 11 Dec 2011 12:33:55 +0000 (12:33 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 11 Dec 2011 12:33:55 +0000 (12:33 +0000)
glstate.py

index 30d749cf53b4f60e2ce5dc2400ca9bf840924174..9497b7a9f03b5dcd364d292a94485afe95d18e21 100644 (file)
@@ -154,9 +154,12 @@ class StateGetter(Visitor):
         elem_type = self.inflector.reduced_type(array.type)
         inflection = self.inflector.inflect(array.type)
         assert inflection.endswith('v')
-        print '    %s %s[%s];' % (elem_type, temp_name, array.length)
+        print '    %s %s[%s + 1];' % (elem_type, temp_name, array.length)
         print '    memset(%s, 0, %s * sizeof *%s);' % (temp_name, array.length, temp_name)
+        print '    %s[%s] = (%s)0xdeadc0de;' % (temp_name, array.length, elem_type)
         print '    %s(%s, %s);' % (inflection + self.suffix, ', '.join(args), temp_name)
+        # Simple buffer overflow detection
+        print '    assert(%s[%s] == (%s)0xdeadc0de);' % (temp_name, array.length, elem_type)
         return temp_name
 
     def visit_opaque(self, pointer, args):