mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-11 07:34:32 +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 *desc )
|
||||
{
|
||||
complete_entry *c =
|
||||
complete_find_exact_entry( cmd, cmd_type );
|
||||
complete_entry *c;
|
||||
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 = malloc( sizeof(complete_entry) )))
|
||||
|
@ -453,6 +460,12 @@ void complete_remove( const wchar_t *cmd,
|
|||
{
|
||||
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 )
|
||||
{
|
||||
enext=e->next;
|
||||
|
@ -598,6 +611,12 @@ int complete_is_valid_option( const wchar_t *str,
|
|||
int gnu_opt_len=0;
|
||||
char *short_validated;
|
||||
|
||||
if( !str || !opt )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Check some generic things like -- and - options.
|
||||
*/
|
||||
|
@ -915,6 +934,12 @@ const wchar_t *complete_get_desc( const wchar_t *filename )
|
|||
{
|
||||
struct stat buf;
|
||||
|
||||
if( !filename )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( !get_desc_buff )
|
||||
{
|
||||
get_desc_buff = sb_halloc( global_context);
|
||||
|
@ -1934,6 +1959,12 @@ void complete( const wchar_t *cmd,
|
|||
|
||||
int cursor_pos = wcslen(cmd );
|
||||
|
||||
if( !cmd || !comp )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
|
||||
error_max=0;
|
||||
|
||||
/**
|
||||
|
|
13
fallback.h
13
fallback.h
|
@ -16,6 +16,19 @@
|
|||
#define WCHAR_MAX INT_MAX
|
||||
#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
|
||||
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;
|
||||
function_data_t *d;
|
||||
|
||||
|
||||
if( !name || !val )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
|
||||
function_remove( name );
|
||||
|
||||
d = malloc( sizeof( function_data_t ) );
|
||||
|
@ -185,6 +192,13 @@ void function_add( const wchar_t *name,
|
|||
|
||||
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) )
|
||||
return 0;
|
||||
|
||||
|
@ -199,6 +213,12 @@ void function_remove( const wchar_t *name )
|
|||
function_data_t *d;
|
||||
event_t ev;
|
||||
|
||||
if( !name )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
|
||||
hash_remove( &function,
|
||||
name,
|
||||
(const void **) &key,
|
||||
|
@ -219,6 +239,13 @@ void function_remove( const wchar_t *name )
|
|||
const wchar_t *function_get_definition( const wchar_t *argv )
|
||||
{
|
||||
function_data_t *data;
|
||||
|
||||
if( !argv )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
|
||||
load( argv );
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
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 )
|
||||
{
|
||||
function_data_t *data;
|
||||
if( !argv )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
|
||||
load( argv );
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
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 )
|
||||
{
|
||||
function_data_t *data;
|
||||
if( !name || !desc )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
|
||||
load( name );
|
||||
data = (function_data_t *)hash_get( &function, name );
|
||||
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 )
|
||||
{
|
||||
if( !list )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return;
|
||||
}
|
||||
|
||||
autoload_names( list, 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 )
|
||||
{
|
||||
function_data_t *data;
|
||||
|
||||
if( !argv )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return 0;
|
||||
}
|
||||
|
||||
load( argv );
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
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 )
|
||||
{
|
||||
function_data_t *data;
|
||||
|
||||
if( !argv )
|
||||
{
|
||||
debug( 0, L"%s called with null input", __func__ );
|
||||
return -1;
|
||||
}
|
||||
|
||||
load( argv );
|
||||
data = (function_data_t *)hash_get( &function, argv );
|
||||
if( data == 0 )
|
||||
|
|
Loading…
Reference in a new issue