]> git.wh0rd.org Git - nano.git/commitdiff
in write_file(), properly handle filenames that contain nulls
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Mon, 27 Nov 2006 05:03:54 +0000 (05:03 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Mon, 27 Nov 2006 05:03:54 +0000 (05:03 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3975 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
src/files.c

index 564d0ecbde53b07b1ae93444be6fc1f8cd3f2142..979746c36c6d1856e80274f129ae1c1af28c5b21 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,8 +3,10 @@ CVS code -
        - Miscellaneous comment fixes. (DLR)
 - files.c:
   do_insertfile()
-       - Properly handle files and executable commands that contain
+       - Properly handle filenames and executable commands that contain
          nulls. (DLR)
+  write_file()
+       - Properly handle filenames that contain nulls. (DLR)
 - nano.h:
        - Rename NANO_ALT_REPLACE_KEY to NANO_REPLACE_ALTKEY, for
          consistency. (DLR)
index c22b5d33057c694dd2c5731eaf3340257c9c4713..dd32130b4b97ba3859222c0005c0b123ad1902ed 100644 (file)
@@ -1275,7 +1275,7 @@ int write_file(const char *name, FILE *f_open, bool tmp, append_type
     int retval = -1;
        /* Instead of returning in this function, you should always
         * merely set retval and then goto cleanup_and_exit. */
-    size_t lineswritten = 0;
+    size_t name_len, lineswritten = 0;
     const filestruct *fileptr = openfile->fileage;
     int fd;
        /* The file descriptor we use. */
@@ -1310,8 +1310,18 @@ int write_file(const char *name, FILE *f_open, bool tmp, append_type
     if (!tmp)
        titlebar(NULL);
 
+    name_len = strlen(name);
+
+    /* Convert newlines to nulls, just before we get the real
+     * filename. */
+    sunder(name);
+
     realname = real_dir_from_tilde(name);
 
+    /* Convert nulls to newlines.  name_len is the string's real
+     * length. */
+    unsunder(name, name_len);
+
 #ifndef DISABLE_OPERATINGDIR
     /* If we're writing a temporary file, we're probably going outside
      * the operating directory, so skip the operating directory test. */