math/gfreduce.[ch]: Fix out-of-bounds memory access. master
authorMark Wooding <mdw@distorted.org.uk>
Fri, 9 Aug 2013 12:22:47 +0000 (13:22 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 9 Aug 2013 12:52:44 +0000 (13:52 +0100)
commit5937940fc6c45b93eb95554996d1cd1b5a1bf307
tree22e03f1cf07bcfad1d242464e39a0b327c23d8d9
parent51f5bbe0bfe8a344c3cc1f5a9fddf885fa75d057
math/gfreduce.[ch]: Fix out-of-bounds memory access.

The final pass of the reduction adds a multiple of the extra top bits
from the most significant word; but at this point, the generated
instruction sequence will access a word one beyond the bottom of the
supplied memory vector.  While it (probably) won't modify this word, it
will still attempt to read and write it.

This is relatively harmless, since typically the vector will have been
allocated from our custom arena, and therefore there'll be a header word
in this position, but hand-built polynomials may cause trouble.

Fix this bug by keeping track of the first instruction which accesses a
word other than the least significant, and using this alternative entry
point in the final pass.  Fortunately, there's an unused slot in the
context structure which we can use for this purpose!

(Yes, the previous refactoring was largely for the purpose of fixing
this bug.)
math/gfreduce.c
math/gfreduce.h
math/t/gfreduce