Module: xenomai-2.6
Branch: master
Commit: 2e952dffc5c59f1d9dfa4218219401ee35967662
URL:    
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=2e952dffc5c59f1d9dfa4218219401ee35967662

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Tue Apr 16 01:12:27 2013 +0200

posix: allow compiling applications with _FORTIFY_SOURCE

When _FORTIFY_SOURCE is set, some services are replaced at compilation time
with versions performing additional checks on their arguments. This is a problem
if the same services need to be wrapped by Xenomai: the checked versions are
not wrapped, causing switches to secondary mode.

This commit provides wrappers for the checked services.

The wrappers simply call the non checked version wrapper: calling glibc checked
services directly would break compilation with libcs without this option, 
meaning
old glibcs and alternative libcs.

In order to enable the checks provided by _FORTIFY_SOURCE, Xenomai itself should
be compiled with this option.

---

 src/skins/posix/posix.wrappers |    6 ++++
 src/skins/posix/printf.c       |   59 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/src/skins/posix/posix.wrappers b/src/skins/posix/posix.wrappers
index 9833077..fbec984 100644
--- a/src/skins/posix/posix.wrappers
+++ b/src/skins/posix/posix.wrappers
@@ -103,3 +103,9 @@
 --wrap malloc
 --wrap free
 --wrap gettimeofday
+--wrap __vfprintf_chk
+--wrap __vprintf_chk
+--wrap __fprintf_chk
+--wrap __printf_chk
+--wrap __vsyslog_chk
+--wrap __syslog_chk
diff --git a/src/skins/posix/printf.c b/src/skins/posix/printf.c
index 8948a31..f30f792 100644
--- a/src/skins/posix/printf.c
+++ b/src/skins/posix/printf.c
@@ -118,3 +118,62 @@ void __wrap_syslog(int priority, const char *fmt, ...)
        __wrap_vsyslog(priority, fmt, args);
        va_end(args);
 }
+
+/* 
+ * Checked versions for -D_FORTIFY_SOURCE
+ *
+ * Do not do any check: if you want to compile your programs with
+ * -D_FORTIFY_SOURCE, you should compile Xenomai with
+ * -D_FORTIFY_SOURCE, so that the call to snprintf in vprint_to_buffer
+ * will in fact do the verifications.
+ *
+ * Forcibly invoking the _chk version of snprintf would break on
+ * alternative libcs such as uclibc where _FORTIFY_SOURCE may not be
+ * available.
+ */
+int __wrap___vfprintf_chk(FILE *f, int flag, const char *fmt, va_list ap)
+{
+       return __wrap_vfprintf(f, fmt, ap);
+}
+int __wrap___vprintf_chk(int flag, const char *fmt, va_list ap)
+{
+       return __wrap_vprintf(fmt, ap);
+}
+
+int __wrap___fprintf_chk(FILE *f, int flag, const char *fmt, ...)
+{
+       va_list args;
+       int ret;
+
+       va_start(args, fmt);
+       ret = __wrap___vfprintf_chk(f, flag, fmt, args);
+       va_end(args);
+
+       return ret;
+}
+
+int __wrap___printf_chk(int flag, const char *fmt, ...)
+{
+       va_list args;
+       int ret;
+
+       va_start(args, fmt);
+       ret = __wrap___vprintf_chk(flag, fmt, args);
+       va_end(args);
+
+       return ret;
+}
+
+void __wrap___vsyslog_chk(int pri, int flag, const char *fmt, va_list ap)
+{
+       __wrap_vsyslog(pri, fmt, ap);
+}
+
+void __wrap___syslog_chk(int pri, int flag, const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       __wrap___vsyslog_chk(pri, flag, fmt, args);
+       va_end(args);
+}


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to