[rtems commit] libio: Do simple parameter checks early

Sebastian Huber sebh at rtems.org
Fri Sep 15 08:59:02 UTC 2017


Module:    rtems
Branch:    master
Commit:    0169e90e8488b1af029486e7215600c87a014fa3
Changeset: http://git.rtems.org/rtems/commit/?id=0169e90e8488b1af029486e7215600c87a014fa3

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Sep 13 08:55:05 2017 +0200

libio: Do simple parameter checks early

This simplifies error handling later.

Update #3132.

---

 cpukit/libcsupport/include/rtems/libio_.h | 14 +++++++-------
 cpukit/libcsupport/src/read.c             |  5 +++--
 cpukit/libcsupport/src/write.c            |  7 ++++---
 testsuites/psxtests/psxfile02/init.c      | 12 +++++++++---
 4 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
index 85f9c8e..9bd8a89 100644
--- a/cpukit/libcsupport/include/rtems/libio_.h
+++ b/cpukit/libcsupport/include/rtems/libio_.h
@@ -871,13 +871,6 @@ static inline ssize_t rtems_libio_iovec_eval(
   int            v;
   rtems_libio_t *iop;
 
-  rtems_libio_check_fd( fd );
-  iop = rtems_libio_iop( fd );
-  rtems_libio_check_is_open( iop );
-  rtems_libio_check_permissions_with_error( iop, flags, EBADF );
-
-  *iopp = iop;
-
   /*
    *  Argument validation on IO vector
    */
@@ -910,6 +903,13 @@ static inline ssize_t rtems_libio_iovec_eval(
     }
   }
 
+  rtems_libio_check_fd( fd );
+  iop = rtems_libio_iop( fd );
+  rtems_libio_check_is_open( iop );
+  rtems_libio_check_permissions_with_error( iop, flags, EBADF );
+
+  *iopp = iop;
+
   return total;
 }
 
diff --git a/cpukit/libcsupport/src/read.c b/cpukit/libcsupport/src/read.c
index a5df6a1..dd3f0c7 100644
--- a/cpukit/libcsupport/src/read.c
+++ b/cpukit/libcsupport/src/read.c
@@ -32,11 +32,12 @@ ssize_t read(
 {
   rtems_libio_t *iop;
 
+  rtems_libio_check_buffer( buffer );
+  rtems_libio_check_count( count );
+
   rtems_libio_check_fd( fd );
   iop = rtems_libio_iop( fd );
   rtems_libio_check_is_open( iop );
-  rtems_libio_check_buffer( buffer );
-  rtems_libio_check_count( count );
   rtems_libio_check_permissions_with_error( iop, LIBIO_FLAGS_READ, EBADF );
 
   /*
diff --git a/cpukit/libcsupport/src/write.c b/cpukit/libcsupport/src/write.c
index c0119a5..8beea64 100644
--- a/cpukit/libcsupport/src/write.c
+++ b/cpukit/libcsupport/src/write.c
@@ -33,13 +33,14 @@ ssize_t write(
   size_t      count
 )
 {
-  rtems_libio_t     *iop;
+  rtems_libio_t *iop;
+
+  rtems_libio_check_buffer( buffer );
+  rtems_libio_check_count( count );
 
   rtems_libio_check_fd( fd );
   iop = rtems_libio_iop( fd );
   rtems_libio_check_is_open( iop );
-  rtems_libio_check_buffer( buffer );
-  rtems_libio_check_count( count );
   rtems_libio_check_permissions_with_error( iop, LIBIO_FLAGS_WRITE, EBADF );
 
   /*
diff --git a/testsuites/psxtests/psxfile02/init.c b/testsuites/psxtests/psxfile02/init.c
index fe74fec..d668152 100644
--- a/testsuites/psxtests/psxfile02/init.c
+++ b/testsuites/psxtests/psxfile02/init.c
@@ -41,10 +41,16 @@ void do_with_fd(
 )
 {
   struct stat       stat_buff;
-  struct iovec      vec[4];
+  struct iovec      vec[2];
+  char              buf[2][1];
   off_t             res;
   int               status;
 
+  vec[0].iov_base = buf[0];
+  vec[0].iov_len = sizeof(buf[0]);
+  vec[1].iov_base = buf[1];
+  vec[1].iov_len = sizeof(buf[1]);
+
   printf("ftruncate %s\n", description);
   status = ftruncate(fd, 40);
   rtems_test_assert( status == -1 );
@@ -88,13 +94,13 @@ void do_with_fd(
   rtems_test_assert( errno == EBADF );
 
   printf("readv %s\n", description);
-  status = readv(fd, vec, 4);
+  status = readv(fd, vec, 2);
   rtems_test_assert( status == -1 );
   printf( "%d: %s\n", errno, strerror( errno ) );
   rtems_test_assert( errno == EBADF );
 
   printf("writev %s\n", description);
-  status = writev(fd, vec, 4);
+  status = writev(fd, vec, 2);
   rtems_test_assert( status == -1 );
   printf( "%d: %s\n", errno, strerror( errno ) );
   rtems_test_assert( errno == EBADF );




More information about the vc mailing list