Code

do not read beyond end of malloc'd buffer
[git.git] / diff.c
diff --git a/diff.c b/diff.c
index 5422c438826254f36d1e00af0e8b882690661276..f90c7a896b814930952c42a7acde55fa8cf20e2b 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1043,8 +1043,16 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
                        emit_line(ecbdata->opt, plain, reset, line, len);
                        fputs("~\n", ecbdata->opt->file);
                } else {
-                       /* don't print the prefix character */
-                       emit_line(ecbdata->opt, plain, reset, line+1, len-1);
+                       /*
+                        * Skip the prefix character, if any.  With
+                        * diff_suppress_blank_empty, there may be
+                        * none.
+                        */
+                       if (line[0] != '\n') {
+                             line++;
+                             len--;
+                       }
+                       emit_line(ecbdata->opt, plain, reset, line, len);
                }
                return;
        }