[rtems commit] libcsupport: Fix TOCTOU in getchark()
Sebastian Huber
sebh at rtems.org
Wed Jul 28 17:06:35 UTC 2021
Module: rtems
Branch: master
Commit: 79b94a2dcd249d575dce9b6c549b710ba8809836
Changeset: http://git.rtems.org/rtems/commit/?id=79b94a2dcd249d575dce9b6c549b710ba8809836
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Wed Jul 28 16:48:59 2021 +0200
libcsupport: Fix TOCTOU in getchark()
Use the same function pointer value to check against NULL and call the
function (if non-NULL).
Fix format, add Doxygen comments, and reduce includes.
---
cpukit/libcsupport/src/getchark.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/cpukit/libcsupport/src/getchark.c b/cpukit/libcsupport/src/getchark.c
index 5a9afbd..cfe9c02 100644
--- a/cpukit/libcsupport/src/getchark.c
+++ b/cpukit/libcsupport/src/getchark.c
@@ -1,8 +1,9 @@
/**
- * @file
+ * @file
*
- * @brief Get Character from Stdin
- * @ingroup libcsupport
+ * @ingroup BSPIO
+ *
+ * @brief This source file contains the implementation of getchark().
*/
/*
@@ -18,13 +19,17 @@
#include "config.h"
#endif
-#include <rtems.h>
#include <rtems/bspIo.h>
-int getchark(void)
+int getchark( void )
{
- if ( BSP_poll_char )
- return (*BSP_poll_char)();
+ BSP_polling_getchar_function_type poll_char;
+
+ poll_char = BSP_poll_char;
+
+ if ( poll_char == NULL ) {
+ return -1;
+ }
- return -1;
+ return ( *poll_char )();
}
More information about the vc
mailing list