diff options
-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); |