changeset 2302:135cc59f82f5

Fix some potential buffer overflows.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 04 Sep 2020 20:42:29 +0300
parents e692cbd3f6da
children ef4bfa756b6c
files colormap.c stitchmap.c
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/colormap.c	Wed Aug 26 13:14:58 2020 +0300
+++ b/colormap.c	Fri Sep 04 20:42:29 2020 +0300
@@ -374,7 +374,7 @@
     size_t i;
     int mch = EOF;
 
-    for (i = 0; i < len && (mch = fgetc(inFile)) != EOF;)
+    for (i = 0; i + 1 < len && (mch = fgetc(inFile)) != EOF;)
     {
         if (mch == endch)
             break;
--- a/stitchmap.c	Wed Aug 26 13:14:58 2020 +0300
+++ b/stitchmap.c	Fri Sep 04 20:42:29 2020 +0300
@@ -273,7 +273,12 @@
 {
     size_t width;
 
-    for (width = 0; width < bufSize && buf[width] && buf[width] != '\r' && buf[width] != '\n'; width++);
+    for (width = 0;
+        width + 1 < bufSize &&
+        buf[width] != 0 &&
+        buf[width] != '\r' &&
+        buf[width] != '\n'; width++);
+
     buf[width] = 0;
 
     return width;