Fix two crash bugs in highlighter/parser for malformed lines (Thanks to Netocrat for the bug report)

darcs-hash:20060703104647-ac50b-9eb649322611a3e7fd95ef5f80acdc25ce09d11a.gz
This commit is contained in:
axel
2006-07-03 20:46:47 +10:00
parent d56ab1d365
commit 7bb070d817
4 changed files with 31 additions and 24 deletions

View File

@@ -884,7 +884,7 @@ void highlight_shell( wchar_t * buff,
wchar_t *token;
parse_util_token_extent( buff, pos, &tok_begin, &tok_end, 0, 0 );
if( tok_begin )
if( tok_begin && tok_end )
{
token = halloc_wcsndup( context, tok_begin, tok_end-tok_begin );

View File

@@ -180,27 +180,27 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
{
wchar_t *begin, *end;
wchar_t *pos;
const wchar_t *cursor = buff + cursor_pos;
CHECK( buff, );
if( a )
*a=0;
*a = (wchar_t *)buff;
if( b )
*b = 0;
*b = (wchar_t *)buff+wcslen(buff);
pos = (wchar_t *)buff;
while( 1 )
{
int bc, ec;
if( parse_util_locate_cmdsubst( pos,
&begin,
&end,
1 ) <= 0)
{
begin=(wchar_t *)buff;
end = (wchar_t *)buff + wcslen(buff);
/*
No subshell found
*/
break;
}
@@ -209,12 +209,13 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
end = (wchar_t *)buff + wcslen(buff);
}
bc = begin-buff;
ec = end-buff;
if(( bc < cursor_pos ) && (ec >= cursor_pos) )
if(( begin < cursor ) && (end >= cursor) )
{
begin++;
if( a )
*a = begin;
if( b )
*b = end;
break;
}
@@ -225,10 +226,7 @@ void parse_util_cmdsubst_extent( const wchar_t *buff,
pos = end+1;
}
if( a )
*a = begin;
if( b )
*b = end;
}
/**
@@ -359,21 +357,21 @@ void parse_util_token_extent( const wchar_t *buff,
if( !end || !begin )
return;
pos = cursor_pos - (begin - buff);
a = (wchar_t *)buff + pos;
b = a;
pa = (wchar_t *)buff + pos;
pb = pa;
assert( begin >= buff );
assert( begin <= (buff+wcslen(buff) ) );
assert( end >= begin );
assert( end <= (buff+wcslen(buff) ) );
buffcpy = wcsndup( begin, end-begin );
if( !buffcpy )
{
DIE_MEM();

View File

@@ -25,7 +25,11 @@ int parse_util_locate_cmdsubst( const wchar_t *in,
int flags );
/**
Find the beginning and end of the command substitution under the cursor
Find the beginning and end of the command substitution under the
cursor. If no subshell is found, the entire string is returned. If
the current command substitution is not ended, i.e. the closing
parenthesis is missing, then the string from the beginning of the
substitution to the end of the string is returned.
\param buff the string to search for subshells
\param cursor_pos the position of the cursor

View File

@@ -261,14 +261,17 @@ The fish parser. Contains functions for parsing code.
*/
struct block_lookup_entry
{
/**
The block type id. The legal values are defined in parser.h.
*/
int type;
/**
The name of the builtin that creates this type of block, if any.
*/
const wchar_t *name;
/**
A description of this block type
*/
@@ -3045,10 +3048,11 @@ int parser_test( const wchar_t * buff,
error( SYNTAX_ERROR,
tok_get_pos( &tok ),
ILLEGAL_CMD_ERR_MSG,
cmd );
tok_last( &tok ) );
print_errors( out, prefix );
}
}
break;
}
if( needs_cmd )
@@ -3257,6 +3261,7 @@ int parser_test( const wchar_t * buff,
sb_printf( out, L"%s", h );
}
}
}
else
{