[Mesa-dev] [PATCH 1/3] amd/common: fix off-by-one in sid_tables.py

Nicolai Hähnle nhaehnle at gmail.com
Mon Jun 12 19:33:05 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

The very last entry in the sid_strings_offsets table ended up missing,
leading to out-of-bounds reads and potential crashes.
---
 src/amd/common/sid_tables.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/amd/common/sid_tables.py b/src/amd/common/sid_tables.py
index fd88d3c..0a2b7ef 100644
--- a/src/amd/common/sid_tables.py
+++ b/src/amd/common/sid_tables.py
@@ -103,21 +103,21 @@ class IntTable:
         self.table += array
         self.idxs.add(idx)
         return idx
 
     def emit(self, filp, name, static=True):
         """
         Write
         [static] const typename name[] = { ... };
         to filp.
         """
-        idxs = sorted(self.idxs) + [-1]
+        idxs = sorted(self.idxs) + [len(self.table)]
 
         fragments = [
             ('\t/* %s */ %s' % (
                 idxs[i],
                 ' '.join((str(elt) + ',') for elt in self.table[idxs[i]:idxs[i+1]])
             ))
             for i in range(len(idxs) - 1)
         ]
 
         filp.write('%sconst %s %s[] = {\n%s\n};\n' % (
-- 
2.9.3



More information about the mesa-dev mailing list