2019-09-30 10:32:12 -04:00
|
|
|
From 68c1a3a7b8277cb225ab221c3a6a4f239b81c9e1 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: shenyangyang <shenyangyang4@huawei.com>
|
|
|
|
|
Date: Mon, 2 Sep 2019 22:30:32 -0400
|
|
|
|
|
Subject: [PATCH] bugfix-Forbidden-non-root-user-to-clear-history
|
|
|
|
|
|
|
|
|
|
---
|
2022-08-15 10:48:02 +08:00
|
|
|
bashhist.c | 5 +++--
|
|
|
|
|
lib/readline/history.c | 8 +++++++-
|
|
|
|
|
lib/readline/history.h | 2 +-
|
|
|
|
|
3 files changed, 11 insertions(+), 4 deletions(-)
|
2019-09-30 10:32:12 -04:00
|
|
|
|
2022-08-15 10:48:02 +08:00
|
|
|
diff --git a/bashhist.c b/bashhist.c
|
2023-07-17 17:08:56 +08:00
|
|
|
index 90cd8c3..7c73492 100644
|
2022-08-15 10:48:02 +08:00
|
|
|
--- a/bashhist.c
|
|
|
|
|
+++ b/bashhist.c
|
|
|
|
|
@@ -345,8 +345,9 @@ load_history ()
|
|
|
|
|
void
|
|
|
|
|
bash_clear_history ()
|
|
|
|
|
{
|
|
|
|
|
- clear_history ();
|
|
|
|
|
- history_lines_this_session = 0;
|
|
|
|
|
+ int ret = clear_history ();
|
|
|
|
|
+ if (ret == 0)
|
|
|
|
|
+ history_lines_this_session = 0;
|
|
|
|
|
/* XXX - reset history_lines_read_from_file? */
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-30 10:32:12 -04:00
|
|
|
diff --git a/lib/readline/history.c b/lib/readline/history.c
|
2023-07-17 17:08:56 +08:00
|
|
|
index 81d4c16..4682a4e 100644
|
2019-09-30 10:32:12 -04:00
|
|
|
--- a/lib/readline/history.c
|
|
|
|
|
+++ b/lib/readline/history.c
|
2023-07-17 17:08:56 +08:00
|
|
|
@@ -597,9 +597,14 @@ history_is_stifled (void)
|
2022-08-15 10:48:02 +08:00
|
|
|
return (history_stifled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-void
|
|
|
|
|
+int
|
2019-09-30 10:32:12 -04:00
|
|
|
clear_history (void)
|
|
|
|
|
{
|
|
|
|
|
+ uid_t uid = getuid();
|
|
|
|
|
+
|
|
|
|
|
+ if (uid)
|
2022-08-15 10:48:02 +08:00
|
|
|
+ return 1;
|
|
|
|
|
+
|
|
|
|
|
register int i;
|
2019-09-30 10:32:12 -04:00
|
|
|
|
|
|
|
|
/* This loses because we cannot free the data. */
|
2023-07-17 17:08:56 +08:00
|
|
|
@@ -611,4 +616,5 @@ clear_history (void)
|
2022-08-15 10:48:02 +08:00
|
|
|
|
|
|
|
|
history_offset = history_length = 0;
|
|
|
|
|
history_base = 1; /* reset history base to default */
|
|
|
|
|
+ return 0;
|
|
|
|
|
}
|
|
|
|
|
diff --git a/lib/readline/history.h b/lib/readline/history.h
|
2023-07-17 17:08:56 +08:00
|
|
|
index 5208f9a..d826658 100644
|
2022-08-15 10:48:02 +08:00
|
|
|
--- a/lib/readline/history.h
|
|
|
|
|
+++ b/lib/readline/history.h
|
2023-07-17 17:08:56 +08:00
|
|
|
@@ -115,7 +115,7 @@ extern histdata_t free_history_entry (HIST_ENTRY *);
|
|
|
|
|
extern HIST_ENTRY *replace_history_entry (int, const char *, histdata_t);
|
2022-08-15 10:48:02 +08:00
|
|
|
|
|
|
|
|
/* Clear the history list and start over. */
|
2023-07-17 17:08:56 +08:00
|
|
|
-extern void clear_history (void);
|
|
|
|
|
+extern int clear_history (void);
|
2022-08-15 10:48:02 +08:00
|
|
|
|
|
|
|
|
/* Stifle the history list, remembering only MAX number of entries. */
|
2023-07-17 17:08:56 +08:00
|
|
|
extern void stifle_history (int);
|
2019-09-30 10:32:12 -04:00
|
|
|
--
|
2023-07-17 17:08:56 +08:00
|
|
|
2.33.0
|
2022-08-15 10:48:02 +08:00
|
|
|
|