bug-indent
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/9] comments.c: Fix print_comment reading past the end of the bu


From: Tim Hentenaar
Subject: [PATCH 2/9] comments.c: Fix print_comment reading past the end of the buffer when reading less than a full comment from stdin.
Date: Wed, 17 Jun 2015 20:55:58 +0200

---
 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 <address@hidden>
        * 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 <address@hidden>
        * 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]