From f8b90b7bdd03a9d4d220b7efb9d08b6cbd9f9662 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 9 Feb 2015 11:02:29 -0500 Subject: [PATCH] commit bash-20150130 snapshot --- CWRU/CWRU.chlog | 10 ++++++- lib/readline/histfile.c | 56 ++++++++++++++++++++++++++++++++++++---- po/._fr.po | Bin 4096 -> 4096 bytes subst.c | 4 +-- tests/RUN-ONE-TEST | 2 +- 5 files changed, 63 insertions(+), 9 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 1028fd393..7d26ecbec 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -7936,4 +7936,12 @@ lib/sh/casemod.c single-byte input character (e.g., `i'). Fix for problem reported by Stephane Chazelas - + 1/31 + ---- +lib/readline/histfile.c + - history_truncate_file, history_do_write: if the first rename(2) + of the history file to the backup file fails, set the backup file + name to NULL to prevent any later attempts to restore the + original. Report from Jonathan Hankins + - history_do_write: don't attempt to back up non-regular files. + Report from Jonathan Hankins diff --git a/lib/readline/histfile.c b/lib/readline/histfile.c index aaab75256..efd8b3375 100644 --- a/lib/readline/histfile.c +++ b/lib/readline/histfile.c @@ -159,12 +159,29 @@ static char * history_backupfile (filename) const char *filename; { - char *ret; + const char *fn; + char *ret, linkbuf[PATH_MAX+1]; size_t len; + ssize_t n; + struct stat fs; - len = strlen (filename); + fn = filename; +#if defined (HAVE_LSTAT) + if (lstat (filename, &fs) == 0 && S_ISLNK (fs.st_mode)) + { + if ((n = readlink (filename, linkbuf, sizeof (linkbuf) - 1)) > 0) + { + linkbuf[n] = '\0'; + fn = linkbuf; + } + else + fn = filename; + } +#endif + + len = strlen (fn); ret = xmalloc (len + 2); - strcpy (ret, filename); + strcpy (ret, fn); ret[len] = '-'; ret[len+1] = '\0'; return ret; @@ -329,6 +346,14 @@ read_history_range (filename, from, to) return (0); } +static int +backup (fn, back) + const char *fn; + const char *back; +{ + return (rename (fn, back)); +} + /* Truncate the history file FNAME, leaving only LINES trailing lines. If FNAME is NULL, then use ~/.history. Returns 0 on success, errno on failure. */ @@ -443,7 +468,14 @@ history_truncate_file (fname, lines) bakname = history_backupfile (filename); if (filename && bakname) - rename (filename, bakname); + { + /* XXX - need to check case where filename is a symlink */ + if (rename (filename, bakname) < 0) + { + free (bakname); /* no backups if rename fails */ + bakname = 0; + } + } if ((file = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600)) != -1) { @@ -509,8 +541,22 @@ history_do_write (filename, nelements, overwrite) bakname = (overwrite && output) ? history_backupfile (output) : 0; exists = output ? (stat (output, &finfo) == 0) : 0; + /* Don't bother backing up if output doesn't exist yet */ + if (exists == 0 || S_ISREG (finfo.st_mode) == 0) + { + free (bakname); /* no backups if not a regular file */ + bakname = 0; + } + if (output && bakname) - rename (output, bakname); + { + /* XXX - need to check case where output is a symlink */ + if (rename (output, bakname) < 0) /* no backups if rename fails */ + { + free (bakname); + bakname = 0; + } + } file = output ? open (output, mode, 0600) : -1; rv = 0; diff --git a/po/._fr.po b/po/._fr.po index d2df2c787f16c920a98b9fafd939d6b8439fd0be..67b5381ad39da4f5a94a44424a68bc2a7260257e 100644 GIT binary patch delta 14 Vc-m`FXi%6C$;@}<)y9}5`~WBd1-SqK delta 14 Vc-m`FXi%6C$;^A>*2b76`~WAz1*`x7 diff --git a/subst.c b/subst.c index e2b57aa29..2ad7d8ff3 100644 --- a/subst.c +++ b/subst.c @@ -5592,8 +5592,8 @@ read_comsub (fd, quoted, rflag) if (c == 0) { -#if 0 - internal_warning ("read_comsub: ignored null byte in input"); +#if 1 + internal_warning ("command substitution: ignored null byte in input"); #endif continue; } diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index 72ec06a2c..3efcf32d6 100755 --- a/tests/RUN-ONE-TEST +++ b/tests/RUN-ONE-TEST @@ -1,4 +1,4 @@ -BUILD_DIR=/usr/local/build/bash/bash-current +BUILD_DIR=/usr/local/build/chet/bash/bash-current THIS_SH=$BUILD_DIR/bash PATH=$PATH:$BUILD_DIR -- 2.47.2