]> git.cameronkatri.com Git - cgit.git/commitdiff
fix segfault when displaying empty blobs
authorEric Wong <normalperson@yhbt.net>
Sun, 15 Mar 2009 01:41:47 +0000 (18:41 -0700)
committerLars Hjemli <hjemli@gmail.com>
Sun, 15 Mar 2009 07:46:15 +0000 (08:46 +0100)
When size is zero, subtracting one from it turns it into
ULONG_MAX which causes an out-of-bounds access on buf.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
ui-tree.c

index c6159ec3df97e059e1cd894202b4173172e9c9c1..553dbaa5a27e60ebad594d23cc842895bdf4beed 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -25,11 +25,14 @@ static void print_text_buffer(char *buf, unsigned long size)
        html("<tr><td class='linenumbers'><pre>");
        idx = 0;
        lineno = 0;
-       htmlf(numberfmt, ++lineno);
-       while(idx < size - 1) { // skip absolute last newline
-               if (buf[idx] == '\n')
-                       htmlf(numberfmt, ++lineno);
-               idx++;
+
+       if (size) {
+               htmlf(numberfmt, ++lineno);
+               while(idx < size - 1) { // skip absolute last newline
+                       if (buf[idx] == '\n')
+                               htmlf(numberfmt, ++lineno);
+                       idx++;
+               }
        }
        html("</pre></td>\n");
        html("<td class='lines'><pre><code>");