A few more error checks during string to integer conversion in various places

darcs-hash:20070109134117-ac50b-8816e238b0b6aa3fe83c0a4695d719a60b0d17d4.gz
This commit is contained in:
axel 2007-01-09 23:41:17 +10:00
parent b70092e281
commit 6e71b5a59c
3 changed files with 122 additions and 90 deletions

8
main.c
View file

@ -195,8 +195,12 @@ static int fish_parse_opt( int argc, char **argv, char **cmd_ptr )
case 'd':
{
char *end;
int tmp = strtol(optarg, &end, 10);
if( tmp >= 0 && tmp <=10 && !*end )
int tmp;
errno = 0;
tmp = strtol(optarg, &end, 10);
if( tmp >= 0 && tmp <=10 && !*end && !errno )
{
debug_level=tmp;
}

View file

@ -112,6 +112,11 @@ The fish parser. Contains functions for parsing and evaluating code.
*/
#define ILLEGAL_CMD_ERR_MSG _( L"Illegal command name '%ls'")
/**
Error message when encountering an illegal file descriptor
*/
#define ILLEGAL_FD_ERR_MSG _( L"Illegal file descriptor '%ls'")
/**
Error message for wildcards with no matches
*/
@ -1366,6 +1371,8 @@ static void parse_job_argument_list( process_t *p,
{
case TOK_PIPE:
{
wchar_t *end;
if( (p->type == INTERNAL_EXEC) )
{
error( SYNTAX_ERROR,
@ -1373,14 +1380,22 @@ static void parse_job_argument_list( process_t *p,
EXEC_ERR_MSG );
return;
}
p->pipe_write_fd = wcstol( tok_last( tok ), 0, 10 );
errno = 0;
p->pipe_write_fd = wcstol( tok_last( tok ), &end, 10 );
if( p->pipe_write_fd < 0 || errno || *end )
{
error( SYNTAX_ERROR,
tok_get_pos( tok ),
ILLEGAL_FD_ERR_MSG,
tok_last( tok ) );
return;
}
if( !p->argv )
halloc_register( j, p->argv = list_to_char_arr( args ) );
p->next = halloc( j, sizeof( process_t ) );
if( p->next == 0 )
{
DIE_MEM();
}
tok_next( tok );
/*
@ -1505,6 +1520,7 @@ static void parse_job_argument_list( process_t *p,
int type = tok_last_type( tok );
io_data_t *new_io;
wchar_t *target = 0;
wchar_t *end;
/*
Don't check redirections in skipped part
@ -1530,9 +1546,20 @@ static void parse_job_argument_list( process_t *p,
if( !new_io )
DIE_MEM();
errno = 0;
new_io->fd = wcstol( tok_last( tok ),
0,
&end,
10 );
if( new_io->fd < 0 || errno || *end )
{
error( SYNTAX_ERROR,
tok_get_pos( tok ),
ILLEGAL_FD_ERR_MSG,
tok_last( tok ) );
}
else
{
tok_next( tok );
switch( tok_last_type( tok ) )
@ -1570,7 +1597,6 @@ static void parse_job_argument_list( process_t *p,
else
{
switch( type )
{
case TOK_REDIRECT_APPEND:
@ -1616,6 +1642,7 @@ static void parse_job_argument_list( process_t *p,
}
break;
}
}
}
}
@ -1677,14 +1704,14 @@ static void parse_job_argument_list( process_t *p,
}
/*
static void print_block_stack( block_t *b )
{
static void print_block_stack( block_t *b )
{
if( !b )
return;
print_block_stack( b->outer );
debug( 0, L"Block type %ls, skip: %d", parser_get_block_desc( b->type ), b->skip );
}
}
*/
/**

View file

@ -103,9 +103,10 @@ int translate_color( char *str )
if( !str )
return -1;
errno = 0;
color = strtol( str, &endptr, 10 );
if(endptr<=str)
if( *endptr || color<0 || errno )
{
int i;
color = -1;