diff options
author | martijn <martijn@cvs.openbsd.org> | 2016-01-25 21:44:02 +0000 |
---|---|---|
committer | martijn <martijn@cvs.openbsd.org> | 2016-01-25 21:44:02 +0000 |
commit | e17daad16a78a1d5dd2cbf6492c08741624ef165 (patch) | |
tree | 4cb9aeb903436036eab6c3e8cb32e9a260fd824a | |
parent | 00932ea9ef5af7011306682fa2f6216dd41e202f (diff) |
Fix a crash as found by sthen@
tested and OK sthen@
OK with minor tweak schwarze@
-rw-r--r-- | usr.bin/tail/forward.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c index 485058af358..e6b8f20b5bb 100644 --- a/usr.bin/tail/forward.c +++ b/usr.bin/tail/forward.c @@ -1,4 +1,4 @@ -/* $OpenBSD: forward.c,v 1.29 2015/11/21 13:58:56 tedu Exp $ */ +/* $OpenBSD: forward.c,v 1.30 2016/01/25 21:44:01 martijn Exp $ */ /* $NetBSD: forward.c,v 1.7 1996/02/13 16:49:10 ghudson Exp $ */ /*- @@ -344,8 +344,18 @@ tfreopen(struct tailfile *tf) { else afiles -= AFILESINCR; } - if (nfiles < afiles) - reopen[nfiles-1] = tf; + if (nfiles <= afiles) { + for (i = 0; i < nfiles - 1; i++) + if (strcmp(reopen[i]->fname, tf->fname) == 0) + break; + if (i < nfiles - 1) + nfiles--; + else + reopen[nfiles-1] = tf; + } else { + warnx("Lost track of %s", ttf->fname); + nfiles--; + } } for (i = 0; i < nfiles; i++) { |