* subshell.c (read_subshell_prompt): Remove argument "how", it's

never set to VISIBLY.  Adjust all dependencies.  Eliminate hack
with "clear_now" - it causes invalid memory access and hides the
real problem.
* util.c (strip_ctrl_codes): Fix possible invalid memory access
if the escape sequence ends unexpectedly.
This commit is contained in:
Pavel Roskin 2002-08-15 06:53:44 +00:00
parent 786c75b683
commit f0dbdeb72e
5 changed files with 31 additions and 19 deletions

View File

@ -1,3 +1,12 @@
2002-08-15 Pavel Roskin <proski@gnu.org>
* subshell.c (read_subshell_prompt): Remove argument "how", it's
never set to VISIBLY. Adjust all dependencies. Eliminate hack
with "clear_now" - it causes invalid memory access and hides the
real problem.
* util.c (strip_ctrl_codes): Fix possible invalid memory access
if the escape sequence ends unexpectedly.
2002-08-14 Pavel Roskin <proski@gnu.org>
* dir.c (do_load_dir): Fix leaking of file descriptors - always

View File

@ -1006,7 +1006,7 @@ directory_history_list (WPanel * panel)
int
load_prompt (int fd, void *unused)
{
if (!read_subshell_prompt (QUIETLY))
if (!read_subshell_prompt ())
return 0;
/* Don't actually change the prompt if it's invisible */

View File

@ -610,11 +610,10 @@ int invoke_subshell (const char *command, int how, char **new_dir)
/* }}} */
/* {{{ read_subshell_prompt */
int read_subshell_prompt (int how)
int read_subshell_prompt (void)
{
/* {{{ Local variables */
int clear_now = FALSE;
static int prompt_size = INITIAL_PROMPT_SIZE;
int bytes = 0, i, rc = 0;
struct timeval timeleft = {0, 0};
@ -650,17 +649,13 @@ int read_subshell_prompt (int how)
/* }}} */
bytes = read (subshell_pty, pty_buffer, pty_buffer_size);
if (how == VISIBLY)
write (STDOUT_FILENO, pty_buffer, bytes);
/* {{{ Extract the prompt from the shell output */
for (i=0; i<bytes; ++i)
if (pty_buffer[i] == '\n' || pty_buffer[i] == '\r'){
prompt_pos = 0;
clear_now = FALSE;
} else {
clear_now = TRUE;
if (!pty_buffer [i])
continue;
@ -670,10 +665,7 @@ int read_subshell_prompt (int how)
prompt_size *= 2);
}
/* Sometimes we get an empty new line and then nothing,
* we better just keep the old prompt instead. */
if (clear_now)
subshell_prompt[prompt_pos] = '\0';
subshell_prompt[prompt_pos] = '\0';
/* }}} */
}

View File

@ -29,7 +29,7 @@ enum {QUIETLY, VISIBLY};
/* Exported functions */
void init_subshell (void);
int invoke_subshell (const char *command, int how, char **new_dir);
int read_subshell_prompt (int how);
int read_subshell_prompt (void);
void resize_subshell (void);
int exit_subshell (void);
void do_subshell_chdir (const char *directory, int update_prompt, int reset_prompt);

View File

@ -789,16 +789,27 @@ char *strip_ctrl_codes (char *s)
if (!s)
return 0;
for (w = s, r = s; *r; ++r)
if (*r != ESC_CHAR){
if (is_printable(*r))
*w++ = *r;
} else {
for (w = s, r = s; *r; ) {
if (*r == ESC_CHAR) {
/* Skip the control sequence's arguments */ ;
if (*(++r) == '[') {
while (strchr ("0123456789;?", *(++r)))
/* Skip the control sequence's arguments */ ;
/* strchr() matches trailing binary 0 */
while (*(++r) && strchr ("0123456789;?", *r));
}
/*
* Now we are at the last character of the sequence.
* Skip it unless it's binary 0.
*/
if (*r)
r++;
continue;
}
if (is_printable(*r))
*w++ = *r;
++r;
}
*w = 0;
return s;
}