]> git.wh0rd.org Git - nano.git/commitdiff
- files.c:save_history() Fix off-by-one bug causing write to unallocated memory ...
authorChris Allegretta <chrisa@asty.org>
Mon, 3 Feb 2003 05:04:09 +0000 (05:04 +0000)
committerChris Allegretta <chrisa@asty.org>
Mon, 3 Feb 2003 05:04:09 +0000 (05:04 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1417 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
files.c

index b4e3ef121ce898d77187ebc1426d46eac55e5b3c..5837472b483cda32e9b45a9c49efd9c7a0181abf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -60,6 +60,8 @@ CVS Code -
          mode on. (DLR; found by David Benbennick)
   save_history()
        - Fix nrealloc return value being ignored (David Benbennick).
+       - Fix off-by-one bug causing write to unallocated memory 
+         (David Benbennick).
 - global.c:
   thanks_for_all_the_fish()
        - Fix compiling with DEBUG and multibuffer (David Benbennick).
diff --git a/files.c b/files.c
index b2d14ea729fb826878911c3620f9116fb907bd93..1ea9bb4b864ca454ec87cc302733898e8557f4a2 100644 (file)
--- a/files.c
+++ b/files.c
@@ -2932,7 +2932,7 @@ void save_history(void)
            chmod(nanohist, S_IRUSR | S_IWUSR);
            /* write oldest first */
            for (h = search_history.tail ; h->prev ; h = h->prev) {
-               h->data = nrealloc(h->data, strlen(h->data) + 1);
+               h->data = nrealloc(h->data, strlen(h->data) + 2);
                strcat(h->data, "\n");
                if (fputs(h->data, hist) == EOF) {
                    rcfile_msg(_("Unable to write ~/.nano_history file, %s"), strerror(errno));
@@ -2944,7 +2944,7 @@ void save_history(void)
                    goto come_from;
            }
            for (h = replace_history.tail ; h->prev ; h = h->prev) {
-               h->data = nrealloc(h->data, strlen(h->data) + 1);
+               h->data = nrealloc(h->data, strlen(h->data) + 2);
                strcat(h->data, "\n");
                if (fputs(h->data, hist) == EOF) {
                    rcfile_msg(_("Unable to write ~/.nano_history file, %s"), strerror(errno));