diff toys/posix/tail.c @ 1536:1d996b0a11c0 draft

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 ef72a16f4b3a
children 3d32f9523584
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--;
           }
         }