Code

debian/patches: Added mem-corruption-fix.dpatch.
authorSebastian Harl <sh@tokkee.org>
Tue, 3 Feb 2009 09:40:23 +0000 (10:40 +0100)
committerSebastian Harl <sh@tokkee.org>
Tue, 3 Feb 2009 09:58:14 +0000 (10:58 +0100)
Upstream patch fixing memory corruption when updating the tree view.

debian/changelog
debian/patches/00list
debian/patches/mem-corruption-fix.dpatch [new file with mode: 0755]

index 4cf93a9263435d0f306c40e65820c645c41716eb..52ad7922c060b187b90aaf1f9aee13845e89da70 100644 (file)
@@ -7,8 +7,10 @@ tig (0.13-1) experimental; urgency=low
       handling of non-UTF-8 locales.
     - Added tigrc-parsing-fix.dpatch - upstream patch fixing a regression in
       parsing ~/.tigrc.
+    - Added mem-corruption-fix.dpatch - upstream patch fixing memory
+      corruption when updating the tree view.
 
- -- Sebastian Harl <sh@tokkee.org>  Tue, 03 Feb 2009 10:37:15 +0100
+ -- Sebastian Harl <sh@tokkee.org>  Tue, 03 Feb 2009 10:39:26 +0100
 
 tig (0.12.1-1) experimental; urgency=low
 
index 8857e8b193155b52dea60d9321d090118528139a..882e105b73406216743401df1519eb0bd3ee9081 100644 (file)
@@ -1,3 +1,4 @@
 non-utf8-fix.dpatch
 tigrc-parsing-fix.dpatch
+mem-corruption-fix.dpatch
 
diff --git a/debian/patches/mem-corruption-fix.dpatch b/debian/patches/mem-corruption-fix.dpatch
new file mode 100755 (executable)
index 0000000..b4fd19b
--- /dev/null
@@ -0,0 +1,60 @@
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## mem-corruption-fix.dpatch by Jonas Fonseca <fonseca@diku.dk>
+##
+## DP: Fix memory corruption bug in tree_read when sorting the entries
+## DP:
+## DP: Triggered by defining ITEM_CHUNK_SIZE to 1.
+
+diff git a/tig.c b/tig.c
+--- a/tig.c
++++ b/tig.c
+@@ -3614,7 +3614,7 @@ static bool
+ {
+       size_t textlen = text ? strlen(text) : 0;
+       char buf[SIZEOF_STR];
+-      unsigned long pos;
++      size_t pos;
+       enum line_type type;
+       bool first_read = view->lines == 0;
+@@ -3645,8 +3645,12 @@ tree_read(struct view *view, char *text)
+                       return FALSE;
+       }
++      if (!add_line_text(view, text, type))
++              return FALSE;
++      text = view->line[view->lines - 1].data;
++
+       /* Skip "Directory ..." and ".." line. */
+-      for (pos = 1 + !!*opt_path; pos < view->lines; pos++) {
++      for (pos = 1 + !!*opt_path; pos < view->lines - 1; pos++) {
+               struct line *line = &view->line[pos];
+               const char *path1 = tree_path(line);
+               char *path2 = text + SIZEOF_TREE_ATTR;
+@@ -3655,24 +3659,16 @@ tree_read(struct view *view, char *text)
+               if (cmp <= 0)
+                       continue;
+-              text = strdup(text);
+-              if (!text)
+-                      return FALSE;
+-
+-              if (view->lines > pos)
++              if (view->lines - 1 > pos)
+                       memmove(&view->line[pos + 1], &view->line[pos],
+-                              (view->lines - pos) * sizeof(*line));
++                              (view->lines - 1 - pos) * sizeof(*line));
+               line = &view->line[pos];
+               line->data = text;
+               line->type = type;
+-              view->lines++;
+               return TRUE;
+       }
+-      if (!add_line_text(view, text, type))
+-              return FALSE;
+-
+       if (tree_lineno > view->lineno) {
+               view->lineno = tree_lineno;
+               tree_lineno = 0;