Fix use after free error spotted by ?ukasz Szpakowski.
authorRob Landley <rob@landley.net>
Tue, 28 Oct 2014 00:20:31 +0000 (19:20 -0500)
committerRob Landley <rob@landley.net>
Tue, 28 Oct 2014 00:20:31 +0000 (19:20 -0500)
toys/posix/tail.c

index e1048be..aba5318 100644 (file)
@@ -176,9 +176,13 @@ static void do_tail(int fd, char *name)
           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--;
           }
         }