1.  fix regexp replacement to handle null matches so we don't loop

2.  fix rest of buffer overflows
