Commit f85a1eb4 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

fix more problems with strings that contain nulls but shouldn't

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3994 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 5ab28f27
Showing with 38 additions and 17 deletions
+38 -17
CVS code - CVS code -
- General: - General:
- Miscellaneous comment fixes. (DLR) - Miscellaneous comment fixes. (DLR)
- browser.c:
do_browser()
- Properly handle directories that contain nulls. (DLR)
- files.c: - files.c:
do_insertfile() do_insertfile()
- Properly handle filenames and executable commands that contain - Properly handle filenames and executable commands that contain
......
...@@ -231,7 +231,9 @@ char *do_browser(char *path, DIR *dir) ...@@ -231,7 +231,9 @@ char *do_browser(char *path, DIR *dir)
#endif #endif
bottombars(browser_list); 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 /* We canceled. Indicate that on the statusbar, and
* blank out ans, since we're done with it. */ * blank out ans, since we're done with it. */
statusbar(_("Cancelled")); statusbar(_("Cancelled"));
...@@ -251,6 +253,11 @@ char *do_browser(char *path, DIR *dir) ...@@ -251,6 +253,11 @@ char *do_browser(char *path, DIR *dir)
* with it. */ * with it. */
ans = mallocstrcpy(ans, ""); 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); new_path = real_dir_from_tilde(answer);
if (new_path[0] != '/') { if (new_path[0] != '/') {
......
...@@ -739,7 +739,7 @@ void do_insertfile( ...@@ -739,7 +739,7 @@ void do_insertfile(
statusbar(_("Cancelled")); statusbar(_("Cancelled"));
break; break;
} else { } else {
size_t pww_save = openfile->placewewant, answer_len; size_t pww_save = openfile->placewewant;
ans = mallocstrcpy(ans, answer); ans = mallocstrcpy(ans, answer);
...@@ -802,11 +802,10 @@ void do_insertfile( ...@@ -802,11 +802,10 @@ void do_insertfile(
} }
#endif #endif
answer_len = strlen(answer); /* Convert newlines to nulls, just before we insert the file
* or execute the command. */
/* Convert newlines to nulls, just before we insert a file
* or execute a command. */
sunder(answer); sunder(answer);
align(&answer);
#ifndef NANO_TINY #ifndef NANO_TINY
if (execute) { if (execute) {
...@@ -842,10 +841,6 @@ void do_insertfile( ...@@ -842,10 +841,6 @@ void do_insertfile(
} }
#endif #endif
/* Convert nulls to newlines. answer_len is answer's real
* length. */
unsunder(answer, answer_len);
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
if (ISSET(MULTIBUFFER)) if (ISSET(MULTIBUFFER))
/* Update the screen to account for the current /* Update the screen to account for the current
...@@ -1885,17 +1880,28 @@ int do_writeout(bool exiting) ...@@ -1885,17 +1880,28 @@ int do_writeout(bool exiting)
#endif #endif
if (append == OVERWRITE) { if (append == OVERWRITE) {
char *full_answer = get_full_path(answer); size_t answer_len = strlen(answer);
char *full_filename = get_full_path(openfile->filename); bool name_exists, different_name;
bool different_name = (strcmp(full_answer, char *full_answer, *full_filename;
full_filename) != 0);
struct stat st; struct stat st;
bool name_exists;
free(full_filename); /* Convert newlines to nulls, just before we get the
free(full_answer); * full path. */
sunder(answer);
name_exists = (stat(answer, &st) != -1); 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 (different_name) {
if (name_exists) { if (name_exists) {
...@@ -1927,6 +1933,11 @@ int do_writeout(bool exiting) ...@@ -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 #ifndef NANO_TINY
/* Here's where we allow the selected text to be written to /* Here's where we allow the selected text to be written to
* a separate file. If we're using restricted mode, this is * a separate file. If we're using restricted mode, this is
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment