math/gfreduce.[ch]: Fix out-of-bounds memory access.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 9 Aug 2013 12:22:47 +0000 (13:22 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 10 Aug 2013 14:28:29 +0000 (15:28 +0100)
commitd153d02efc56bef4c5d553700aea44e1a8481185
tree22e03f1cf07bcfad1d242464e39a0b327c23d8d9
parent8e663045cd18e14e99affd3f904170dc686fd76c
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, `liv', 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