don't allow filenames entered at the "Write File" prompt or the "Insert
File" prompt to contain nulls git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3971 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
b6c4dbffdb
commit
50d78a6f9a
|
@ -1,6 +1,10 @@
|
||||||
CVS code -
|
CVS code -
|
||||||
- General:
|
- General:
|
||||||
- Miscellaneous comment fixes. (DLR)
|
- Miscellaneous comment fixes. (DLR)
|
||||||
|
- Don't allow filenames entered at the "Write File" prompt or
|
||||||
|
the "Insert File" prompt to contain nulls. Changes to
|
||||||
|
do_statusbar_input(), do_statusbar_output(), and
|
||||||
|
do_statusbar_verbatim_input(). (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)
|
||||||
|
|
15
src/nano.c
15
src/nano.c
|
@ -1553,14 +1553,13 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
|
||||||
current_len = strlen(openfile->current->data);
|
current_len = strlen(openfile->current->data);
|
||||||
|
|
||||||
while (i < output_len) {
|
while (i < output_len) {
|
||||||
/* If allow_cntrls is FALSE, filter out nulls and newlines,
|
/* Null to newline, if needed, and if allow_cntrls is TRUE. */
|
||||||
* since they're ASCII control characters. */
|
if (output[i] == '\0') {
|
||||||
if (allow_cntrls) {
|
if (allow_cntrls)
|
||||||
/* Null to newline, if needed. */
|
|
||||||
if (output[i] == '\0')
|
|
||||||
output[i] = '\n';
|
output[i] = '\n';
|
||||||
/* Newline to Enter, if needed. */
|
/* Newline to Enter, if needed, and if allow_cntrls is TRUE. */
|
||||||
else if (output[i] == '\n') {
|
} else if (output[i] == '\n') {
|
||||||
|
if (allow_cntrls) {
|
||||||
do_enter();
|
do_enter();
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1579,7 +1578,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* If the NO_NEWLINES flag isn't set, when a character is
|
/* If the NO_NEWLINES flag isn't set, when a character is
|
||||||
* added to the magicline, it means we need a new magicline! */
|
* added to the magicline, it means we need a new magicline. */
|
||||||
if (!ISSET(NO_NEWLINES) && openfile->filebot ==
|
if (!ISSET(NO_NEWLINES) && openfile->filebot ==
|
||||||
openfile->current)
|
openfile->current)
|
||||||
new_magicline();
|
new_magicline();
|
||||||
|
|
40
src/prompt.c
40
src/prompt.c
|
@ -145,7 +145,7 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
|
||||||
if (*s_or_t || get_key_buffer_len() == 0) {
|
if (*s_or_t || get_key_buffer_len() == 0) {
|
||||||
if (kbinput != NULL) {
|
if (kbinput != NULL) {
|
||||||
/* Display all the characters in the input buffer at
|
/* Display all the characters in the input buffer at
|
||||||
* once, filtering out control characters. */
|
* once, filtering out control characters and nulls. */
|
||||||
char *output = charalloc(kbinput_len + 1);
|
char *output = charalloc(kbinput_len + 1);
|
||||||
size_t i;
|
size_t i;
|
||||||
bool got_enter;
|
bool got_enter;
|
||||||
|
@ -156,7 +156,7 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
|
||||||
output[i] = '\0';
|
output[i] = '\0';
|
||||||
|
|
||||||
do_statusbar_output(output, kbinput_len, &got_enter,
|
do_statusbar_output(output, kbinput_len, &got_enter,
|
||||||
FALSE);
|
FALSE, FALSE);
|
||||||
|
|
||||||
free(output);
|
free(output);
|
||||||
|
|
||||||
|
@ -312,11 +312,11 @@ bool do_statusbar_mouse(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The user typed output_len multibyte characters. Add them to the
|
/* The user typed output_len multibyte characters. Add them to the
|
||||||
* statusbar prompt, setting got_enter to TRUE if we get a newline, and
|
* statusbar prompt, setting got_enter to TRUE if we get a newline,
|
||||||
* filtering out all ASCII control characters if allow_cntrls is
|
* filtering out all ASCII control characters if allow_cntrls is TRUE,
|
||||||
* TRUE. */
|
* and filtering out all nulls if allow_nulls is TRUE. */
|
||||||
void do_statusbar_output(char *output, size_t output_len, bool
|
void do_statusbar_output(char *output, size_t output_len, bool
|
||||||
*got_enter, bool allow_cntrls)
|
*got_enter, bool allow_cntrls, bool allow_nulls)
|
||||||
{
|
{
|
||||||
size_t answer_len, i = 0;
|
size_t answer_len, i = 0;
|
||||||
char *char_buf = charalloc(mb_cur_max());
|
char *char_buf = charalloc(mb_cur_max());
|
||||||
|
@ -328,14 +328,14 @@ void do_statusbar_output(char *output, size_t output_len, bool
|
||||||
*got_enter = FALSE;
|
*got_enter = FALSE;
|
||||||
|
|
||||||
while (i < output_len) {
|
while (i < output_len) {
|
||||||
/* If allow_cntrls is FALSE, filter out nulls and newlines,
|
/* Null to newline, if needed, and if allow_cntrls and
|
||||||
* since they're ASCII control characters. */
|
* allow_nulls are TRUE. */
|
||||||
if (allow_cntrls) {
|
if (output[i] == '\0') {
|
||||||
/* Null to newline, if needed. */
|
if (allow_cntrls && allow_nulls)
|
||||||
if (output[i] == '\0')
|
|
||||||
output[i] = '\n';
|
output[i] = '\n';
|
||||||
/* Newline to Enter, if needed. */
|
/* Newline to Enter, if needed, and if allow_cntrls is TRUE. */
|
||||||
else if (output[i] == '\n') {
|
} else if (output[i] == '\n') {
|
||||||
|
if (allow_cntrls) {
|
||||||
/* Set got_enter to TRUE to indicate that we got the
|
/* Set got_enter to TRUE to indicate that we got the
|
||||||
* Enter key, put back the rest of the characters in
|
* Enter key, put back the rest of the characters in
|
||||||
* output so that they can be parsed and output again,
|
* output so that they can be parsed and output again,
|
||||||
|
@ -352,9 +352,10 @@ void do_statusbar_output(char *output, size_t output_len, bool
|
||||||
i += char_buf_len;
|
i += char_buf_len;
|
||||||
|
|
||||||
/* If allow_cntrls is FALSE, filter out an ASCII control
|
/* If allow_cntrls is FALSE, filter out an ASCII control
|
||||||
* character. */
|
* character. If allow_nulls is FALSE, filter out a null. */
|
||||||
if (!allow_cntrls && is_ascii_cntrl_char(*(output + i -
|
if ((!allow_cntrls && is_ascii_cntrl_char(*(output + i -
|
||||||
char_buf_len)))
|
char_buf_len))) || (!allow_nulls && *(output + i -
|
||||||
|
char_buf_len) == '\0'))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* More dangerousness fun =) */
|
/* More dangerousness fun =) */
|
||||||
|
@ -676,14 +677,17 @@ void do_statusbar_verbatim_input(bool *got_enter)
|
||||||
kbinput = get_verbatim_kbinput(bottomwin, &kbinput_len);
|
kbinput = get_verbatim_kbinput(bottomwin, &kbinput_len);
|
||||||
|
|
||||||
/* Display all the verbatim characters at once, not filtering out
|
/* Display all the verbatim characters at once, not filtering out
|
||||||
* control characters. */
|
* control characters, and not filtering out nulls unless we're at
|
||||||
|
* the "Write File" prompt or the "Insert File" prompt. */
|
||||||
output = charalloc(kbinput_len + 1);
|
output = charalloc(kbinput_len + 1);
|
||||||
|
|
||||||
for (i = 0; i < kbinput_len; i++)
|
for (i = 0; i < kbinput_len; i++)
|
||||||
output[i] = (char)kbinput[i];
|
output[i] = (char)kbinput[i];
|
||||||
output[i] = '\0';
|
output[i] = '\0';
|
||||||
|
|
||||||
do_statusbar_output(output, kbinput_len, got_enter, TRUE);
|
do_statusbar_output(output, kbinput_len, got_enter, TRUE,
|
||||||
|
currshortcut != writefile_list && currshortcut !=
|
||||||
|
insertfile_list);
|
||||||
|
|
||||||
free(output);
|
free(output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -496,7 +496,7 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
|
||||||
bool do_statusbar_mouse(void);
|
bool do_statusbar_mouse(void);
|
||||||
#endif
|
#endif
|
||||||
void do_statusbar_output(char *output, size_t output_len, bool
|
void do_statusbar_output(char *output, size_t output_len, bool
|
||||||
*got_enter, bool allow_cntrls);
|
*got_enter, bool allow_cntrls, bool allow_nulls);
|
||||||
void do_statusbar_home(void);
|
void do_statusbar_home(void);
|
||||||
void do_statusbar_end(void);
|
void do_statusbar_end(void);
|
||||||
void do_statusbar_left(void);
|
void do_statusbar_left(void);
|
||||||
|
|
Loading…
Reference in New Issue