aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/tail.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-10-27 19:20:31 -0500
committerRob Landley <rob@landley.net>2014-10-27 19:20:31 -0500
commitde36079ccdceffee0ed750ab8780b0c68925ba2f (patch)
treec550db4d385d38aeca904ca3a2864ff225555554 /toys/posix/tail.c
parent45b3882a1187f0e957efbc4fc5d797ba9603f545 (diff)
downloadtoybox-de36079ccdceffee0ed750ab8780b0c68925ba2f.tar.gz
Fix use after free error spotted by ?ukasz Szpakowski.
Diffstat (limited to 'toys/posix/tail.c')
-rw-r--r--toys/posix/tail.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/toys/posix/tail.c b/toys/posix/tail.c
index e1048be7..aba53180 100644
--- a/toys/posix/tail.c
+++ b/toys/posix/tail.c
@@ -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--;
}
}