[PATCH 06/18] libio: Do simple parameter checks early
Sebastian Huber
sebastian.huber at embedded-brains.de
Wed Sep 13 13:39:39 UTC 2017
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 85f9c8e0a5..9bd8a8979c 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 a5df6a1140..dd3f0c7128 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 c0119a54e4..8beea6494a 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 fe74fec7d5..d66815203a 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 );
--
2.12.3
More information about the devel
mailing list