diff options
author | James Vega <jamessan@jamessan.com> | 2005-12-16 03:21:22 +1000 |
---|---|---|
committer | James Vega <jamessan@jamessan.com> | 2005-12-16 03:21:22 +1000 |
commit | a91bf6d88ace4e0fe8281b3b59dd9406d7cb01e0 (patch) | |
tree | 6d15ee2b48fcdf3645df6c3eb23574c27ae564ec /builtin.c | |
parent | fa75fc390162c19d9cc15c12e7c99e9301c89409 (diff) |
builtin.c: builtin_source now checks that its argument is a file.
Without this check, it would be possible to attempt to source a directory and get stuck in an infinite loop.
darcs-hash:20051215172122-35ec8-b3ce05d8d7ee9534edf92b74ca842d034b894e8a.gz
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -2163,6 +2163,7 @@ static int builtin_source( wchar_t ** argv ) { int fd; int res; + struct stat buf; if( (argv[1] == 0) || (argv[2]!=0) ) { @@ -2173,6 +2174,19 @@ static int builtin_source( wchar_t ** argv ) return 1; } + if( wstat(argv[1], &buf) == -1 ) + { + builtin_wperror( L"stat" ); + res = 1; + } + + if( !S_ISREG(buf.st_mode) ) + { + sb_append2( sb_err, argv[0], L": Expected a regular file\n", (void *)0 ); + builtin_print_help( argv[0], sb_err ); + + return 1; + } if( ( fd = wopen( argv[1], O_RDONLY ) ) == -1 ) { builtin_wperror( L"open" ); |