From 58f3fab9598c531ea1ea4e13702abb8d87b75bf2 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 22 Jul 2011 16:04:38 +0000 Subject: 2011-07-22 Joel Sherrill PR 1839/filesystem * libcsupport/include/rtems/libio_.h, libcsupport/src/fchdir.c, libcsupport/src/fdatasync.c, libcsupport/src/fpathconf.c, libcsupport/src/fsync.c, libcsupport/src/ftruncate.c, libcsupport/src/read.c, libcsupport/src/readv.c, libcsupport/src/write.c, libcsupport/src/writev.c: Some calls did not return proper status for permission errors or incorrectly permissions at all. --- cpukit/libcsupport/include/rtems/libio_.h | 17 ++++++++++++++--- cpukit/libcsupport/src/fchdir.c | 8 +------- cpukit/libcsupport/src/fdatasync.c | 4 ++-- cpukit/libcsupport/src/fpathconf.c | 3 +-- cpukit/libcsupport/src/fsync.c | 3 +-- cpukit/libcsupport/src/ftruncate.c | 3 +-- cpukit/libcsupport/src/read.c | 4 ++-- cpukit/libcsupport/src/readv.c | 4 ++-- cpukit/libcsupport/src/write.c | 4 ++-- cpukit/libcsupport/src/writev.c | 4 ++-- 10 files changed, 28 insertions(+), 26 deletions(-) (limited to 'cpukit/libcsupport') diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h index e9a7dd3cb8..e0396daa24 100644 --- a/cpukit/libcsupport/include/rtems/libio_.h +++ b/cpukit/libcsupport/include/rtems/libio_.h @@ -123,19 +123,30 @@ extern rtems_libio_t *rtems_libio_iop_freelist; } while (0) /* - * rtems_libio_check_permissions + * rtems_libio_check_permissions_with_error * * Macro to check if a file descriptor is open for this operation. + * On failure, return the user specified error. */ -#define rtems_libio_check_permissions(_iop, _flag) \ +#define rtems_libio_check_permissions_with_error(_iop, _flag, _errno) \ do { \ if (((_iop)->flags & (_flag)) == 0) { \ - rtems_set_errno_and_return_minus_one( EINVAL ); \ + rtems_set_errno_and_return_minus_one( _errno ); \ return -1; \ } \ } while (0) +/* + * rtems_libio_check_permissions + * + * Macro to check if a file descriptor is open for this operation. + * On failure, return EINVAL + */ + +#define rtems_libio_check_permissions(_iop, _flag) \ + rtems_libio_check_permissions_with_error(_iop, _flag, EINVAL ) + /* * rtems_filesystem_freenode * diff --git a/cpukit/libcsupport/src/fchdir.c b/cpukit/libcsupport/src/fchdir.c index 3c53d653e3..c95e2b7fb3 100644 --- a/cpukit/libcsupport/src/fchdir.c +++ b/cpukit/libcsupport/src/fchdir.c @@ -1,7 +1,7 @@ /* * fchdir() - compatible with SVr4, 4.4BSD and X/OPEN - Change Directory * - * COPYRIGHT (c) 1989-2000. + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -35,12 +35,6 @@ int fchdir( iop = rtems_libio_iop( fd ); rtems_libio_check_is_open(iop); - /* - * Now process the fchmod(). - */ - - rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); - /* * Verify you can change directory into this node. */ diff --git a/cpukit/libcsupport/src/fdatasync.c b/cpukit/libcsupport/src/fdatasync.c index de226af5c1..f29084794b 100644 --- a/cpukit/libcsupport/src/fdatasync.c +++ b/cpukit/libcsupport/src/fdatasync.c @@ -1,7 +1,7 @@ /* * fdatasync() - POSIX 1003.1b 6.6.2 - Synchronize the Data of a File * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -29,7 +29,7 @@ int fdatasync( rtems_libio_check_fd( fd ); iop = rtems_libio_iop( fd ); rtems_libio_check_is_open(iop); - rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); + rtems_libio_check_permissions_with_error( iop, LIBIO_FLAGS_WRITE, EBADF ); /* * Now process the fdatasync(). diff --git a/cpukit/libcsupport/src/fpathconf.c b/cpukit/libcsupport/src/fpathconf.c index accaae1585..71edaf6ce9 100644 --- a/cpukit/libcsupport/src/fpathconf.c +++ b/cpukit/libcsupport/src/fpathconf.c @@ -1,7 +1,7 @@ /* * fpathconf() - POSIX 1003.1b - 5.7.1 - Configurable Pathname Varables * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -33,7 +33,6 @@ long fpathconf( rtems_libio_check_fd(fd); iop = rtems_libio_iop(fd); rtems_libio_check_is_open(iop); - rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); /* * Now process the information request. diff --git a/cpukit/libcsupport/src/fsync.c b/cpukit/libcsupport/src/fsync.c index 4d2fe2ae12..75d0faadb0 100644 --- a/cpukit/libcsupport/src/fsync.c +++ b/cpukit/libcsupport/src/fsync.c @@ -1,7 +1,7 @@ /* * fsync() - POSIX 1003.1b 6.6.1 - Synchronize the State of a File * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -29,7 +29,6 @@ int fsync( rtems_libio_check_fd( fd ); iop = rtems_libio_iop( fd ); rtems_libio_check_is_open(iop); - rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); /* * Now process the fsync(). diff --git a/cpukit/libcsupport/src/ftruncate.c b/cpukit/libcsupport/src/ftruncate.c index 64946d7bb6..9c50ca2fbe 100644 --- a/cpukit/libcsupport/src/ftruncate.c +++ b/cpukit/libcsupport/src/ftruncate.c @@ -32,6 +32,7 @@ int ftruncate( rtems_libio_check_fd( fd ); iop = rtems_libio_iop( fd ); rtems_libio_check_is_open(iop); + rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); /* * Now process the ftruncate() request. @@ -45,7 +46,5 @@ int ftruncate( if ( (*loc.ops->node_type_h)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY ) rtems_set_errno_and_return_minus_one( EISDIR ); - rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); - return (*iop->pathinfo.handlers->ftruncate_h)( iop, length ); } diff --git a/cpukit/libcsupport/src/read.c b/cpukit/libcsupport/src/read.c index f4c3bdc322..ec296afb46 100644 --- a/cpukit/libcsupport/src/read.c +++ b/cpukit/libcsupport/src/read.c @@ -1,7 +1,7 @@ /* * read() - POSIX 1003.1b 6.4.1 - Read From a File * - * COPYRIGHT (c) 1989-2010. + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -32,7 +32,7 @@ ssize_t read( rtems_libio_check_is_open( iop ); rtems_libio_check_buffer( buffer ); rtems_libio_check_count( count ); - rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); + rtems_libio_check_permissions_with_error( iop, LIBIO_FLAGS_READ, EBADF ); /* * Now process the read(). diff --git a/cpukit/libcsupport/src/readv.c b/cpukit/libcsupport/src/readv.c index 6b33760504..172297a374 100644 --- a/cpukit/libcsupport/src/readv.c +++ b/cpukit/libcsupport/src/readv.c @@ -5,7 +5,7 @@ * * http://www.opengroup.org/onlinepubs/009695399/functions/readv.html * - * COPYRIGHT (c) 1989-2007. + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -40,7 +40,7 @@ ssize_t readv( rtems_libio_check_fd( fd ); iop = rtems_libio_iop( fd ); rtems_libio_check_is_open( iop ); - rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); + rtems_libio_check_permissions_with_error( iop, LIBIO_FLAGS_READ, EBADF ); /* * Argument validation on IO vector diff --git a/cpukit/libcsupport/src/write.c b/cpukit/libcsupport/src/write.c index b723f426b6..f289cbae90 100644 --- a/cpukit/libcsupport/src/write.c +++ b/cpukit/libcsupport/src/write.c @@ -1,7 +1,7 @@ /* * write() - POSIX 1003.1b 6.4.2 - Write to a File * - * COPYRIGHT (c) 1989-2010. + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -39,7 +39,7 @@ ssize_t write( rtems_libio_check_is_open( iop ); rtems_libio_check_buffer( buffer ); rtems_libio_check_count( count ); - rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); + rtems_libio_check_permissions_with_error( iop, LIBIO_FLAGS_WRITE, EBADF ); /* * Now process the write() request. diff --git a/cpukit/libcsupport/src/writev.c b/cpukit/libcsupport/src/writev.c index 380e325365..6ac2cea424 100644 --- a/cpukit/libcsupport/src/writev.c +++ b/cpukit/libcsupport/src/writev.c @@ -5,7 +5,7 @@ * * http://www.opengroup.org/onlinepubs/009695399/functions/writev.html * - * COPYRIGHT (c) 1989-2007. + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -41,7 +41,7 @@ ssize_t writev( rtems_libio_check_fd( fd ); iop = rtems_libio_iop( fd ); rtems_libio_check_is_open( iop ); - rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); + rtems_libio_check_permissions_with_error( iop, LIBIO_FLAGS_WRITE, EBADF ); /* * Argument validation on IO vector -- cgit v1.2.3