aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfram Sang <w.sang@pengutronix.de>2010-11-15 02:58:28 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-11-15 02:58:28 +0100
commit2e9aeae4dbc7bd45640ac472ee6ecb7eaf89fe8d (patch)
tree77d6991b64e7b67820f9524c7b0f8a856b904d23
parent6696eac274b5dcf5932b211fe9ee748d8268a39c (diff)
downloadbusybox-w32-2e9aeae4dbc7bd45640ac472ee6ecb7eaf89fe8d.tar.gz
busybox-w32-2e9aeae4dbc7bd45640ac472ee6ecb7eaf89fe8d.tar.bz2
busybox-w32-2e9aeae4dbc7bd45640ac472ee6ecb7eaf89fe8d.zip
lineedit: create history files with mode 0600
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/lineedit.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 68006ffba..d6c33541e 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1336,7 +1336,7 @@ static void save_history(char *str)
1336 int fd; 1336 int fd;
1337 int len, len2; 1337 int len, len2;
1338 1338
1339 fd = open(state->hist_file, O_WRONLY | O_CREAT | O_APPEND, 0666); 1339 fd = open(state->hist_file, O_WRONLY | O_CREAT | O_APPEND, 0600);
1340 if (fd < 0) 1340 if (fd < 0)
1341 return; 1341 return;
1342 xlseek(fd, 0, SEEK_END); /* paranoia */ 1342 xlseek(fd, 0, SEEK_END); /* paranoia */
@@ -1351,10 +1351,8 @@ static void save_history(char *str)
1351 /* did we write so much that history file needs trimming? */ 1351 /* did we write so much that history file needs trimming? */
1352 state->cnt_history_in_file++; 1352 state->cnt_history_in_file++;
1353 if (state->cnt_history_in_file > MAX_HISTORY * 4) { 1353 if (state->cnt_history_in_file > MAX_HISTORY * 4) {
1354 FILE *fp;
1355 char *new_name; 1354 char *new_name;
1356 line_input_t *st_temp; 1355 line_input_t *st_temp;
1357 int i;
1358 1356
1359 /* we may have concurrently written entries from others. 1357 /* we may have concurrently written entries from others.
1360 * load them */ 1358 * load them */
@@ -1364,8 +1362,12 @@ static void save_history(char *str)
1364 1362
1365 /* write out temp file and replace hist_file atomically */ 1363 /* write out temp file and replace hist_file atomically */
1366 new_name = xasprintf("%s.%u.new", state->hist_file, (int) getpid()); 1364 new_name = xasprintf("%s.%u.new", state->hist_file, (int) getpid());
1367 fp = fopen_for_write(new_name); 1365 fd = open(state->hist_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
1368 if (fp) { 1366 if (fd >= 0) {
1367 FILE *fp;
1368 int i;
1369
1370 fp = xfdopen_for_write(fd);
1369 for (i = 0; i < st_temp->cnt_history; i++) 1371 for (i = 0; i < st_temp->cnt_history; i++)
1370 fprintf(fp, "%s\n", st_temp->history[i]); 1372 fprintf(fp, "%s\n", st_temp->history[i]);
1371 fclose(fp); 1373 fclose(fp);