--- ChangeLog | 2 ++ regression/TEST | 8 ++++++++ src/comments.c | 4 ++++ 3 files changed, 14 insertions(+)
diff --git a/ChangeLog b/ChangeLog index bada7d7..672b3db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ 2015-06-16 Tim Hentenaar <t...@hentenaar.com> * Use want_blank instead of copying a space to e_code to avoid double spaces. + * Fix print_comment reading past the end of the buffer when reading + less than a full comment from stdin. 2015-06-15 Tim Hentenaar <t...@hentenaar.com> * Added -par to -kr. diff --git a/regression/TEST b/regression/TEST index 7b2fc0e..3f9b86d 100755 --- a/regression/TEST +++ b/regression/TEST @@ -424,6 +424,14 @@ echo Testing new comment stuff...Done. echo Testing bad code handling.... +# print_comment() was reading past the end of the buffer... +echo -ne '/*' | $INDENT -npro -st > /dev/null 2>&1 +if [ $? -ne 0 ] +then + echo "ERROR: print_comment reads past the end of the buffer." | tee -a $ERR + echo >> $ERR +fi + # This ends in a error from indent but it shouldn't coredump. $INDENT -npro input/bug206785.c -o output/bug206785.c 2>output/bug206785.err diff --git a/src/comments.c b/src/comments.c index cb53d40..bf860b7 100644 --- a/src/comments.c +++ b/src/comments.c @@ -199,6 +199,10 @@ extern void print_comment( CHECK_COM_SIZE; } while ((*buf_ptr != '*') && (buf_ptr < buf_end)); + /* Make sure we don't go past the end of the buffer */ + if (buf_ptr > buf_end) + buf_ptr = buf_end; + /* We have reached the end of the comment, and it's all on * this line. */ -- 2.3.6 _______________________________________________ bug-indent mailing list bug-indent@gnu.org https://lists.gnu.org/mailman/listinfo/bug-indent