#!/usr/bin/perl -w
#
-# $OpenBSD: recover,v 1.11 2016/11/05 16:21:56 afresh1 Exp $
+# $OpenBSD: recover,v 1.12 2018/02/03 15:44:36 millert Exp $
#
# Script to (safely) recover nvi edit sessions.
#
foreach $file (readdir(RECDIR)) {
next unless $file =~ /^recover\./;
- if (!sysopen(RECFILE, $file, O_RDONLY|O_NOFOLLOW)) {
+ if (!sysopen(RECFILE, $file, O_RDONLY|O_NOFOLLOW|O_NONBLOCK)) {
warn "$0: can't open $file: $!\n";
next;
}
#
# Delete anything that is not a regular file as that is either
# filesystem corruption from fsck or an exploit attempt.
+ # Real vi recovery files are created with mode 0600, ignore others.
#
if (!stat(RECFILE)) {
warn "$0: can't stat $file: $!\n";
close(RECFILE);
next;
}
+ if (((stat(_))[2] & 07777) != 0600) {
+ close(RECFILE);
+ next;
+ }
$owner = (stat(_))[4];
if (! -f _ || ! -s _) {
unlink($file) unless -d _;