]> git.wh0rd.org Git - nano.git/commitdiff
fix more problems with strings that contain nulls but shouldn't
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Mon, 11 Dec 2006 22:11:32 +0000 (22:11 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Mon, 11 Dec 2006 22:11:32 +0000 (22:11 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3994 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
src/browser.c
src/files.c

index 952daf08b6ddb5711ae40718a12f09636fb650bf..34f3b610a42646e345717c6357303470a2132587 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
 CVS code -
 - General:
        - Miscellaneous comment fixes. (DLR)
+- browser.c:
+  do_browser()
+       - Properly handle directories that contain nulls. (DLR)
 - files.c:
   do_insertfile()
        - Properly handle filenames and executable commands that contain
index ef0d9133d20d6b9710f059cda7c15bb9ed396148..a37cf599a092dfd47f7edccfa980cfacf70a3399 100644 (file)
@@ -231,7 +231,9 @@ char *do_browser(char *path, DIR *dir)
 #endif
                bottombars(browser_list);
 
-               if (i < 0) {
+               /* If the directory begins with a newline (i.e. an
+                * encoded null), treat it as though it's blank. */
+               if (i < 0 || answer[0] == '\n') {
                    /* We canceled.  Indicate that on the statusbar, and
                     * blank out ans, since we're done with it. */
                    statusbar(_("Cancelled"));
@@ -251,6 +253,11 @@ char *do_browser(char *path, DIR *dir)
                 * with it. */
                ans = mallocstrcpy(ans, "");
 
+               /* Convert newlines to nulls, just before we go to the
+                * directory. */
+               sunder(answer);
+               align(&answer);
+
                new_path = real_dir_from_tilde(answer);
 
                if (new_path[0] != '/') {
index d027eec2f04fae5e9ca36cb58abc63b00f61e7d2..10e069eb7a5e9f610dd1771de4896357da2746c6 100644 (file)
@@ -739,7 +739,7 @@ void do_insertfile(
            statusbar(_("Cancelled"));
            break;
        } else {
-           size_t pww_save = openfile->placewewant, answer_len;
+           size_t pww_save = openfile->placewewant;
 
            ans = mallocstrcpy(ans, answer);
 
@@ -802,11 +802,10 @@ void do_insertfile(
            }
 #endif
 
-           answer_len = strlen(answer);
-
-           /* Convert newlines to nulls, just before we insert a file
-            * or execute a command. */
+           /* Convert newlines to nulls, just before we insert the file
+            * or execute the command. */
            sunder(answer);
+           align(&answer);
 
 #ifndef NANO_TINY
            if (execute) {
@@ -842,10 +841,6 @@ void do_insertfile(
            }
 #endif
 
-           /* Convert nulls to newlines.  answer_len is answer's real
-            * length. */
-           unsunder(answer, answer_len);
-
 #ifdef ENABLE_MULTIBUFFER
            if (ISSET(MULTIBUFFER))
                /* Update the screen to account for the current
@@ -1885,17 +1880,28 @@ int do_writeout(bool exiting)
 #endif
 
            if (append == OVERWRITE) {
-               char *full_answer = get_full_path(answer);
-               char *full_filename = get_full_path(openfile->filename);
-               bool different_name = (strcmp(full_answer,
-                       full_filename) != 0);
+               size_t answer_len = strlen(answer);
+               bool name_exists, different_name;
+               char *full_answer, *full_filename;
                struct stat st;
-               bool name_exists;
 
-               free(full_filename);
-               free(full_answer);
+               /* Convert newlines to nulls, just before we get the
+                * full path. */
+               sunder(answer);
 
                name_exists = (stat(answer, &st) != -1);
+               full_answer = get_full_path(answer);
+
+               /* Convert nulls to newlines.  answer_len is the
+                * string's real length. */
+               unsunder(answer, answer_len);
+
+               full_filename = get_full_path(openfile->filename);
+               different_name = (strcmp(full_answer,
+                       full_filename) != 0);
+
+               free(full_filename);
+               free(full_answer);
 
                if (different_name) {
                    if (name_exists) {
@@ -1927,6 +1933,11 @@ int do_writeout(bool exiting)
                }
            }
 
+           /* Convert newlines to nulls, just before we save the
+            * file. */
+           sunder(answer);
+           align(&answer);
+
 #ifndef NANO_TINY
            /* Here's where we allow the selected text to be written to
             * a separate file.  If we're using restricted mode, this is