Make sure failed tilde expansion doesn't result in evaluating null strings in highlighting code

darcs-hash:20060620211621-ac50b-3d57cc28272f5222fb42a72f0f98f89af1ec60de.gz
This commit is contained in:
axel 2006-06-21 07:16:21 +10:00
parent 5688035680
commit 51c6c5ea49

View file

@ -80,87 +80,90 @@ static int is_potential_path( const wchar_t *path )
void *context = halloc( 0, 0 ); void *context = halloc( 0, 0 );
tilde = expand_tilde( wcsdup(path) ); tilde = expand_tilde( wcsdup(path) );
halloc_register( context, tilde ); if( tilde )
unescaped = unescape( tilde, 1 );
if( unescaped )
{ {
halloc_register( context, tilde );
// debug( 1, L"%ls -> %ls ->%ls", path, tilde, unescaped );
halloc_register( context, unescaped ); unescaped = unescape( tilde, 1 );
if( unescaped )
for( in = out = unescaped; *in; in++ )
{ {
switch( *in )
{
case PROCESS_EXPAND:
case VARIABLE_EXPAND:
case VARIABLE_EXPAND_SINGLE:
case BRACKET_BEGIN:
case BRACKET_END:
case BRACKET_SEP:
{
has_magic = 1;
break;
}
case INTERNAL_SEPARATOR:
{
break;
}
default:
{
*(out++) = *in;
break;
}
}
} // debug( 1, L"%ls -> %ls ->%ls", path, tilde, unescaped );
*out = 0;
if( !has_magic && wcslen( unescaped ) )
{
int must_be_dir = 0;
DIR *dir;
must_be_dir = unescaped[wcslen(unescaped)-1] == L'/';
if( must_be_dir )
{
dir = wopendir( unescaped );
res = !!dir;
closedir( dir );
}
else
{
wchar_t *dir_name, *base;
struct wdirent *ent;
dir_name = wdirname( halloc_wcsdup(context, unescaped) );
base = wbasename( halloc_wcsdup(context, unescaped) );
if( (wcscmp( dir_name, L"/" ) == 0 ) && halloc_register( context, unescaped );
(wcscmp( base, L"/" ) == 0 ) )
for( in = out = unescaped; *in; in++ )
{
switch( *in )
{ {
res = 1; case PROCESS_EXPAND:
} case VARIABLE_EXPAND:
else if( (dir = wopendir( dir_name )) ) case VARIABLE_EXPAND_SINGLE:
{ case BRACKET_BEGIN:
case BRACKET_END:
while( (ent = wreaddir( dir )) ) case BRACKET_SEP:
{ {
if( wcsncmp( ent->d_name, base, wcslen(base) ) == 0 ) has_magic = 1;
{ break;
res = 1;
break;
}
} }
case INTERNAL_SEPARATOR:
{
break;
}
default:
{
*(out++) = *in;
break;
}
}
}
*out = 0;
if( !has_magic && wcslen( unescaped ) )
{
int must_be_dir = 0;
DIR *dir;
must_be_dir = unescaped[wcslen(unescaped)-1] == L'/';
if( must_be_dir )
{
dir = wopendir( unescaped );
res = !!dir;
closedir( dir ); closedir( dir );
} }
} else
{
wchar_t *dir_name, *base;
struct wdirent *ent;
dir_name = wdirname( halloc_wcsdup(context, unescaped) );
base = wbasename( halloc_wcsdup(context, unescaped) );
if( (wcscmp( dir_name, L"/" ) == 0 ) &&
(wcscmp( base, L"/" ) == 0 ) )
{
res = 1;
}
else if( (dir = wopendir( dir_name )) )
{
while( (ent = wreaddir( dir )) )
{
if( wcsncmp( ent->d_name, base, wcslen(base) ) == 0 )
{
res = 1;
break;
}
}
closedir( dir );
}
}
}
} }
} }