From a983798295fce79ebd9bc62f10cde2b0356dbbbb Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 15 Jun 2006 10:59:31 +1000 Subject: [PATCH] Fix segfault caused by a backslash followed by a null inside single quotes darcs-hash:20060615005931-ac50b-4c6be7129dfd2c3a5759a811b605ad32fceff758.gz --- common.c | 4 +++- highlight.c | 8 ++++++-- parse_util.c | 11 +++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/common.c b/common.c index f2c8f18e2..69dccb781 100644 --- a/common.c +++ b/common.c @@ -445,13 +445,15 @@ wchar_t *quote_end( const wchar_t *pos ) while( 1 ) { pos++; - + if( !*pos ) return 0; if( *pos == L'\\') { pos++; + if( !*pos ) + return 0; } else { diff --git a/highlight.c b/highlight.c index 53a130611..586e7e7e3 100644 --- a/highlight.c +++ b/highlight.c @@ -72,12 +72,15 @@ static int is_potential_path( const wchar_t *path ) void *context = halloc( 0, 0 ); tilde = expand_tilde( wcsdup(path) ); + halloc_register( context, tilde ); unescaped = unescape( tilde, 1 ); + if( unescaped ) + { + // debug( 1, L"%ls -> %ls ->%ls", path, tilde, unescaped ); halloc_register( context, unescaped ); - halloc_register( context, tilde ); for( in = out = unescaped; *in; in++ ) { @@ -110,7 +113,7 @@ static int is_potential_path( const wchar_t *path ) } *out = 0; - if( !has_magic ) + if( !has_magic && wcslen( unescaped ) ) { int must_be_dir = 0; DIR *dir; @@ -151,6 +154,7 @@ static int is_potential_path( const wchar_t *path ) } } + } halloc_free( context ); diff --git a/parse_util.c b/parse_util.c index c9ac4e5a5..ce02d8354 100644 --- a/parse_util.c +++ b/parse_util.c @@ -100,7 +100,7 @@ int parse_util_locate_cmdsubst( const wchar_t *in, wchar_t *paran_begin=0, *paran_end=0; - for( pos=(wchar_t *)in; *pos; pos++ ) + for( pos = (wchar_t *)in; *pos; pos++ ) { if( prev != '\\' ) { @@ -112,7 +112,9 @@ int parse_util_locate_cmdsubst( const wchar_t *in, pos=q_end; } else + { break; + } } else { @@ -141,7 +143,6 @@ int parse_util_locate_cmdsubst( const wchar_t *in, } } - prev = *pos; } @@ -212,6 +213,12 @@ void parse_util_cmdsubst_extent( const wchar_t *buff, begin++; break; } + + if( !*end ) + { + break; + } + pos = end+1; } if( a )