mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-13 08:27:26 +00:00
Do input validation in various functions in function.c and complete.c
darcs-hash:20060608000145-ac50b-1088c3f5e3c1ad2759c13400e5dda2d21858fedc.gz
This commit is contained in:
parent
d7eb084b9d
commit
93ae00e8e5
3 changed files with 105 additions and 2 deletions
35
complete.c
35
complete.c
|
@ -385,10 +385,17 @@ void complete_add( const wchar_t *cmd,
|
||||||
const wchar_t *comp,
|
const wchar_t *comp,
|
||||||
const wchar_t *desc )
|
const wchar_t *desc )
|
||||||
{
|
{
|
||||||
complete_entry *c =
|
complete_entry *c;
|
||||||
complete_find_exact_entry( cmd, cmd_type );
|
|
||||||
complete_entry_opt *opt;
|
complete_entry_opt *opt;
|
||||||
|
|
||||||
|
if( !cmd )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = complete_find_exact_entry( cmd, cmd_type );
|
||||||
|
|
||||||
if( c == 0 )
|
if( c == 0 )
|
||||||
{
|
{
|
||||||
if( !(c = malloc( sizeof(complete_entry) )))
|
if( !(c = malloc( sizeof(complete_entry) )))
|
||||||
|
@ -453,6 +460,12 @@ void complete_remove( const wchar_t *cmd,
|
||||||
{
|
{
|
||||||
complete_entry *e, *eprev=0, *enext=0;
|
complete_entry *e, *eprev=0, *enext=0;
|
||||||
|
|
||||||
|
if( !cmd )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for( e = first_entry; e; e=enext )
|
for( e = first_entry; e; e=enext )
|
||||||
{
|
{
|
||||||
enext=e->next;
|
enext=e->next;
|
||||||
|
@ -598,6 +611,12 @@ int complete_is_valid_option( const wchar_t *str,
|
||||||
int gnu_opt_len=0;
|
int gnu_opt_len=0;
|
||||||
char *short_validated;
|
char *short_validated;
|
||||||
|
|
||||||
|
if( !str || !opt )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check some generic things like -- and - options.
|
Check some generic things like -- and - options.
|
||||||
*/
|
*/
|
||||||
|
@ -915,6 +934,12 @@ const wchar_t *complete_get_desc( const wchar_t *filename )
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
|
if( !filename )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if( !get_desc_buff )
|
if( !get_desc_buff )
|
||||||
{
|
{
|
||||||
get_desc_buff = sb_halloc( global_context);
|
get_desc_buff = sb_halloc( global_context);
|
||||||
|
@ -1934,6 +1959,12 @@ void complete( const wchar_t *cmd,
|
||||||
|
|
||||||
int cursor_pos = wcslen(cmd );
|
int cursor_pos = wcslen(cmd );
|
||||||
|
|
||||||
|
if( !cmd || !comp )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
error_max=0;
|
error_max=0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
13
fallback.h
13
fallback.h
|
@ -16,6 +16,19 @@
|
||||||
#define WCHAR_MAX INT_MAX
|
#define WCHAR_MAX INT_MAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
Make sure __func__ is defined to some string. This should be the
|
||||||
|
currently compiled function, but not all compilers support this
|
||||||
|
feature.
|
||||||
|
*/
|
||||||
|
#if __STDC_VERSION__ < 199901L
|
||||||
|
# if __GNUC__ >= 2
|
||||||
|
# define __func__ __FUNCTION__
|
||||||
|
# else
|
||||||
|
# define __func__ "<unknown>"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Under curses, tputs expects an int (*func)(char) as its last
|
Under curses, tputs expects an int (*func)(char) as its last
|
||||||
parameter, but in ncurses, tputs expects a int (*func)(int) as its
|
parameter, but in ncurses, tputs expects a int (*func)(int) as its
|
||||||
|
|
59
function.c
59
function.c
|
@ -157,6 +157,13 @@ void function_add( const wchar_t *name,
|
||||||
wchar_t *cmd_end;
|
wchar_t *cmd_end;
|
||||||
function_data_t *d;
|
function_data_t *d;
|
||||||
|
|
||||||
|
|
||||||
|
if( !name || !val )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
function_remove( name );
|
function_remove( name );
|
||||||
|
|
||||||
d = malloc( sizeof( function_data_t ) );
|
d = malloc( sizeof( function_data_t ) );
|
||||||
|
@ -185,6 +192,13 @@ void function_add( const wchar_t *name,
|
||||||
|
|
||||||
int function_exists( const wchar_t *cmd )
|
int function_exists( const wchar_t *cmd )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if( !cmd )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if( parser_is_reserved(cmd) )
|
if( parser_is_reserved(cmd) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -199,6 +213,12 @@ void function_remove( const wchar_t *name )
|
||||||
function_data_t *d;
|
function_data_t *d;
|
||||||
event_t ev;
|
event_t ev;
|
||||||
|
|
||||||
|
if( !name )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hash_remove( &function,
|
hash_remove( &function,
|
||||||
name,
|
name,
|
||||||
(const void **) &key,
|
(const void **) &key,
|
||||||
|
@ -219,6 +239,13 @@ void function_remove( const wchar_t *name )
|
||||||
const wchar_t *function_get_definition( const wchar_t *argv )
|
const wchar_t *function_get_definition( const wchar_t *argv )
|
||||||
{
|
{
|
||||||
function_data_t *data;
|
function_data_t *data;
|
||||||
|
|
||||||
|
if( !argv )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
load( argv );
|
load( argv );
|
||||||
data = (function_data_t *)hash_get( &function, argv );
|
data = (function_data_t *)hash_get( &function, argv );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
|
@ -229,6 +256,12 @@ const wchar_t *function_get_definition( const wchar_t *argv )
|
||||||
const wchar_t *function_get_desc( const wchar_t *argv )
|
const wchar_t *function_get_desc( const wchar_t *argv )
|
||||||
{
|
{
|
||||||
function_data_t *data;
|
function_data_t *data;
|
||||||
|
if( !argv )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
load( argv );
|
load( argv );
|
||||||
data = (function_data_t *)hash_get( &function, argv );
|
data = (function_data_t *)hash_get( &function, argv );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
|
@ -240,6 +273,12 @@ const wchar_t *function_get_desc( const wchar_t *argv )
|
||||||
void function_set_desc( const wchar_t *name, const wchar_t *desc )
|
void function_set_desc( const wchar_t *name, const wchar_t *desc )
|
||||||
{
|
{
|
||||||
function_data_t *data;
|
function_data_t *data;
|
||||||
|
if( !name || !desc )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
load( name );
|
load( name );
|
||||||
data = (function_data_t *)hash_get( &function, name );
|
data = (function_data_t *)hash_get( &function, name );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
|
@ -294,6 +333,12 @@ static void get_names_internal_all( const void *key,
|
||||||
|
|
||||||
void function_get_names( array_list_t *list, int get_hidden )
|
void function_get_names( array_list_t *list, int get_hidden )
|
||||||
{
|
{
|
||||||
|
if( !list )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
autoload_names( list, get_hidden );
|
autoload_names( list, get_hidden );
|
||||||
|
|
||||||
if( get_hidden )
|
if( get_hidden )
|
||||||
|
@ -310,6 +355,13 @@ void function_get_names( array_list_t *list, int get_hidden )
|
||||||
const wchar_t *function_get_definition_file( const wchar_t *argv )
|
const wchar_t *function_get_definition_file( const wchar_t *argv )
|
||||||
{
|
{
|
||||||
function_data_t *data;
|
function_data_t *data;
|
||||||
|
|
||||||
|
if( !argv )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
load( argv );
|
load( argv );
|
||||||
data = (function_data_t *)hash_get( &function, argv );
|
data = (function_data_t *)hash_get( &function, argv );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
|
@ -322,6 +374,13 @@ const wchar_t *function_get_definition_file( const wchar_t *argv )
|
||||||
int function_get_definition_offset( const wchar_t *argv )
|
int function_get_definition_offset( const wchar_t *argv )
|
||||||
{
|
{
|
||||||
function_data_t *data;
|
function_data_t *data;
|
||||||
|
|
||||||
|
if( !argv )
|
||||||
|
{
|
||||||
|
debug( 0, L"%s called with null input", __func__ );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
load( argv );
|
load( argv );
|
||||||
data = (function_data_t *)hash_get( &function, argv );
|
data = (function_data_t *)hash_get( &function, argv );
|
||||||
if( data == 0 )
|
if( data == 0 )
|
||||||
|
|
Loading…
Reference in a new issue