in do_insertfile(), properly handle files that contain nulls

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3974 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2006-11-27 04:57:22 +00:00
parent 81371020bb
commit d97649859d
2 changed files with 13 additions and 12 deletions

View File

@ -3,7 +3,8 @@ CVS code -
- Miscellaneous comment fixes. (DLR) - Miscellaneous comment fixes. (DLR)
- files.c: - files.c:
do_insertfile() do_insertfile()
- Properly handle executable commands that contain nulls. (DLR) - Properly handle files and executable commands that contain
nulls. (DLR)
- nano.h: - nano.h:
- Rename NANO_ALT_REPLACE_KEY to NANO_REPLACE_ALTKEY, for - Rename NANO_ALT_REPLACE_KEY to NANO_REPLACE_ALTKEY, for
consistency. (DLR) consistency. (DLR)

View File

@ -683,7 +683,7 @@ void do_insertfile(
char *ans = mallocstrcpy(NULL, ""); char *ans = mallocstrcpy(NULL, "");
/* The last answer the user typed on the statusbar. */ /* The last answer the user typed on the statusbar. */
filestruct *edittop_save = openfile->edittop; filestruct *edittop_save = openfile->edittop;
size_t current_x_save = openfile->current_x; size_t current_x_save = openfile->current_x, answer_len;
ssize_t current_y_save = openfile->current_y; ssize_t current_y_save = openfile->current_y;
bool at_edittop = FALSE; bool at_edittop = FALSE;
/* Whether we're at the top of the edit window. */ /* Whether we're at the top of the edit window. */
@ -800,27 +800,23 @@ void do_insertfile(
} }
#endif #endif
answer_len = strlen(answer);
/* Convert newlines to nulls, just before we execute a
* command. */
sunder(answer);
#ifndef NANO_TINY #ifndef NANO_TINY
if (execute) { if (execute) {
size_t answer_len = strlen(answer);
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
if (ISSET(MULTIBUFFER)) if (ISSET(MULTIBUFFER))
/* Open a blank buffer. */ /* Open a blank buffer. */
open_buffer(""); open_buffer("");
#endif #endif
/* Convert newlines to nulls, just before we execute a
* command. */
sunder(answer);
/* Save the command's output in the current buffer. */ /* Save the command's output in the current buffer. */
execute_command(answer); execute_command(answer);
/* 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)) {
/* Move back to the beginning of the first line of /* Move back to the beginning of the first line of
@ -844,6 +840,10 @@ 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