changeset 1536:1d996b0a11c0

Fix use after free error spotted by ?ukasz Szpakowski.
author Rob Landley <rob@landley.net>
date Mon, 27 Oct 2014 19:20:31 -0500
parents b50de98c9708
children a6ef79b31829
files toys/posix/tail.c
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/toys/posix/tail.c	Mon Oct 27 18:08:59 2014 -0500
+++ b/toys/posix/tail.c	Mon Oct 27 19:20:31 2014 -0500
@@ -176,9 +176,13 @@
           linepop = try[count] == '\n';
 
           if (lines > 0) {
+            char c;
+
             do {
+              c = *list->data;
               if (!--(list->len)) free(dlist_pop(&list));
-            } while (*(list->data++) != '\n');
+              else list->data++;
+            } while (c != '\n');
             lines--;
           }
         }