OBS User unknown 2007-11-15 14:19:48 +00:00 committed by Git OBS Bridge
parent 2f74b01825
commit ee20985191
3 changed files with 45 additions and 16 deletions

View File

@ -1,5 +1,5 @@
--- cmdbuf.c
+++ cmdbuf.c 2007-11-14 19:07:11.216430000 +0100
+++ cmdbuf.c 2007-11-15 12:38:14.513106799 +0100
@@ -14,11 +14,16 @@
* Used only by command() and related functions.
*/
@ -51,13 +51,18 @@
filename = histfile_name();
if (filename == NULL)
@@ -1460,25 +1475,50 @@ save_cmdhist()
@@ -1458,27 +1473,71 @@ save_cmdhist()
if (mlist_shell.modified)
modified = 1;
#endif
if (!modified)
- if (!modified)
+ if (!modified) {
+ free(filename);
return;
- f = fopen(filename, "w");
- free(filename);
- if (f == NULL)
+ }
+#if HAVE_STAT
+ /* Do not overwrite other users history files due `su' */
+ st.st_dev = st.st_ino = 0;
@ -70,30 +75,47 @@
+ ? (st.st_mode & 0020)
+ : (st.st_mode & 0002))))
+ {
+ free(filename);
+ return;
+ }
+#endif
+ tempname = malloc((strlen(filename)+strlen("XXXXXX"))*sizeof(char)+2);
+ if (tempname == NULL) {
+ free(filename);
+ return;
+ }
+ sprintf(tempname, "%s.XXXXXX", filename);
+ (void)mktemp(tempname);
+ if (*tempname == '\0') {
+ free(filename);
+ free(tempname);
return;
-#if HAVE_FCHMOD
- /* Make history file readable only by owner. */
- fchmod(fileno(f), 0600);
+ }
#endif
+ tempname = malloc((strlen(filename)+strlen("XXXXXX"))*sizeof(char)+2);
+ if (tempname == NULL)
+ return;
+ sprintf(tempname, "%s.XXXXXX", filename);
+ (void)mktemp(tempname);
- fprintf(f, "%s\n", HISTFILE_FIRST_LINE);
+
+ umask_save = umask(077);
+#if HAVE_STAT
+ fd = open(tempname, O_CREAT|O_EXCL|O_WRONLY|O_NOFOLLOW, (int)((st.st_mode & 0777) | 0600));
+ fd = open(tempname, O_CREAT|O_EXCL|O_WRONLY|O_NOFOLLOW, ((st.st_mode & 0777) | 0600));
+#else
+ fd = open(tempname, O_CREAT|O_EXCL|O_WRONLY|O_NOFOLLOW, 0600));
+#endif
#endif
+ (void)umask(umask_save);
+ f = fdopen(fd, "w");
+ if (f == NULL)
- fprintf(f, "%s\n", HISTFILE_FIRST_LINE);
+ if (fd < 0) {
+ free(filename);
+ free(tempname);
+ return;
+ }
+ f = fdopen(fd, "w");
+ if (f == NULL) {
+ free(filename);
+ free(tempname);
+ return;
+ }
+ setbuf(f, buf);
+ fprintf(f, "%s\n", HISTFILE_FIRST_LINE);
fprintf(f, "%s\n", HISTFILE_SEARCH_SECTION);

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Thu Nov 15 12:42:33 CET 2007 - werner@suse.de
- Avoid memory leaks in case of an error during saving history
-------------------------------------------------------------------
Wed Nov 14 19:10:18 CET 2007 - werner@suse.de

View File

@ -21,7 +21,7 @@ Provides: normal-less jless
Requires: file
AutoReqProv: on
Version: 409
Release: 5
Release: 7
Summary: Text File Browser and Pager Similar to more
Url: http://www.greenwoodsoftware.com/less/
Source: %{name}-%{version}.tar.bz2
@ -109,6 +109,8 @@ rm -rf $RPM_BUILD_ROOT
%config %{sysconfdir}/*
%{prefix}/bin/*
%changelog
* Thu Nov 15 2007 - werner@suse.de
- Avoid memory leaks in case of an error during saving history
* Wed Nov 14 2007 - werner@suse.de
- Speed up the history save by using a temorary file and make the
stream of that file a full buffered one.