From 3dbef48a77da47b6a134a3086f01b15cc6fd480a Mon Sep 17 00:00:00 2001 From: Dennis Groenen Date: Sun, 31 Jul 2011 14:23:07 +0200 Subject: [PATCH 1/1] finishing touches to ash history buffer patch --- debian/patches/ash-history-buffer.patch | 48 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/debian/patches/ash-history-buffer.patch b/debian/patches/ash-history-buffer.patch index 4b1d2a4..e0b0477 100644 --- a/debian/patches/ash-history-buffer.patch +++ b/debian/patches/ash-history-buffer.patch @@ -33,14 +33,14 @@ + const char *tmphistory = lookupvar("HISTFILE"); + const char *storedhistory = lookupvar("STOREDHISTFILE"); + -+ if (storedhistory) /* is NULL when setting up the history buffer failed; check this before copying */ ++ if (storedhistory) /* is NULL when setting up the history buffer failed; check for this before copying */ + copy_file(tmphistory, storedhistory, FILEUTILS_FORCE | FILEUTILS_DEREFERENCE | FILEUTILS_PRESERVE_STATUS); +#endif + status = exitstatus; TRACE(("pid %d, exitshell(%d)\n", getpid(), status)); if (setjmp(loc.loc)) { -@@ -13056,9 +13082,61 @@ int ash_main(int argc UNUSED_PARAM, char +@@ -13056,9 +13082,59 @@ int ash_main(int argc UNUSED_PARAM, char if (hp == NULL) { hp = lookupvar("HOME"); if (hp != NULL) { @@ -54,34 +54,32 @@ + tmphistory = concat_path_file(tmppath, ".ash_history"); + storedhistory = concat_path_file(hp, ".ash_history"); + -+ if (access(tmphistory, R_OK | W_OK) == -1) { -+ if (access(CONFIG_ASH_HIST_BUFFER_PATH, R_OK == -1)) { -+ bb_simple_perror_msg("could not access history buffer path"); -+ goto bail; -+ } -+ if (bb_make_directory(tmppath, 0700, FILEUTILS_RECUR)) { -+ /* bb_make_directory is noisy, no need for an additional error message here */ -+ goto bail; -+ } -+ if (access(storedhistory, R_OK) == -1) { -+ creat(tmphistory, 0644); -+ } else { -+ copy_file(storedhistory, tmphistory, FILEUTILS_FORCE | FILEUTILS_DEREFERENCE | FILEUTILS_PRESERVE_STATUS); -+ } -+ } else { /* (security) checks before reusing existing temporary history file */ -+ struct stat stat_tmphistory; -+ lstat(tmphistory, &stat_tmphistory); -+ if (!S_ISREG(stat_tmphistory.st_mode)) { -+ errno = 0; -+ bb_simple_perror_msg("history buffer is not a regular file"); -+ goto bail; -+ } -+ if (stat_tmphistory.st_uid != geteuid() || stat_tmphistory.st_gid != getegid()) { ++ if (access(CONFIG_ASH_HIST_BUFFER_PATH, R_OK == -1)) { ++ bb_simple_perror_msg("could not access history buffer path"); ++ goto bail; ++ } ++ ++ if (bb_make_directory(tmppath, S_IRWXU, FILEUTILS_RECUR)) { ++ /* bb_make_directory is noisy, no need for an additional error message */ ++ goto bail; ++ } else { ++ struct stat stat_tmppath; ++ stat(tmppath, &stat_tmppath); ++ if (stat_tmppath.st_uid != geteuid() || stat_tmppath.st_mode & (S_IRWXG | S_IRWXO)) { + errno = 0; + bb_simple_perror_msg("history buffer is not exclusive to the shell user"); + goto bail; + } + } ++ ++ if (access(tmphistory, R_OK | W_OK) == -1) { ++ if (access(storedhistory, R_OK) != -1) { ++ if (copy_file(storedhistory, tmphistory, FILEUTILS_FORCE | FILEUTILS_DEREFERENCE | FILEUTILS_PRESERVE_STATUS) == -1) { ++ /* copy_file is noisy too, no need for an additional error message */ ++ goto bail; ++ } ++ } ++ } + setvar("STOREDHISTFILE", storedhistory, 0); + goto out; + -- 1.7.9.5