diff options
author | 2017-08-11 19:37:58 +0000 | |
---|---|---|
committer | 2017-08-11 19:37:58 +0000 | |
commit | 2c60786ab405b7cd788ab3dd9348582e8abba786 (patch) | |
tree | eb5fbbdf667e808f6fe1a2861206176ae4967aae | |
parent | Fix cross builds: no clang depend target, no DESTDIR on HOSTCC build (diff) | |
download | wireguard-openbsd-2c60786ab405b7cd788ab3dd9348582e8abba786.tar.xz wireguard-openbsd-2c60786ab405b7cd788ab3dd9348582e8abba786.zip |
Check whether the first two characters of $HISTFILE are the magic
characters of the old binary ksh history file. In that case ignore
the history file after displaying an error once. Prevents annoying
repeated 'history file is corrupt' messages in $HOME on NFS setups
suffered by henning and makes the migration from the old to the new
history file format safer.
ok henning, tweaks & ok jca
-rw-r--r-- | bin/ksh/history.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/bin/ksh/history.c b/bin/ksh/history.c index f3a6daa9c33..04521c73656 100644 --- a/bin/ksh/history.c +++ b/bin/ksh/history.c @@ -1,4 +1,4 @@ -/* $OpenBSD: history.c,v 1.63 2017/08/01 14:30:05 deraadt Exp $ */ +/* $OpenBSD: history.c,v 1.64 2017/08/11 19:37:58 tb Exp $ */ /* * command history @@ -709,9 +709,14 @@ history_load(Source *s) return 0; } +#define HMAGIC1 0xab +#define HMAGIC2 0xcd + void hist_init(Source *s) { + int oldmagic1, oldmagic2; + if (Flag(FTALKING) == 0) return; @@ -727,6 +732,22 @@ hist_init(Source *s) if (histfh == NULL) return; + oldmagic1 = fgetc(histfh); + oldmagic2 = fgetc(histfh); + + if (oldmagic1 == EOF || oldmagic2 == EOF) { + if (!feof(histfh) && ferror(histfh)) { + history_close(); + return; + } + } else if (oldmagic1 == HMAGIC1 && oldmagic2 == HMAGIC2) { + bi_errorf("ignoring old style history file"); + history_close(); + return; + } + + rewind(histfh); + history_load(s); history_lock(LOCK_UN); |