This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 3/6] Reinstantiate fd range check if and only if defined _STRICT_FD_SIZE_CHECK=1


From: KOSAKI Motohiro <kosaki.motohiro@gmail.com>

---
 ChangeLog           |   13 +++++++++++++
 Versions.def        |    1 +
 debug/Makefile      |    6 +++++-
 debug/Versions      |    3 +++
 debug/fdelt_chk.c   |   10 ++++++++++
 debug/tst-chk1.c    |    6 +++---
 debug/tst-chk7.c    |    3 +++
 debug/tst-lfschk7.c |    2 ++
 misc/bits/select2.h |    8 ++++----
 misc/sys/select.h   |    2 +-
 10 files changed, 45 insertions(+), 9 deletions(-)
 create mode 100644 debug/tst-chk7.c
 create mode 100644 debug/tst-lfschk7.c

diff --git a/ChangeLog b/ChangeLog
index e1902c0..0dd8601 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2013-03-25  KOSAKI Motohiro  <kosaki.motohiro@gmail.com>
 
+	* debug/fdelt_chk.c (__fdelt_check): New.
+	* misc/bits/select2.h (__FD_ELT): Uses __fdelt_check and
+	__fdelt_check_warn instead of __fdelt_chk and __fdelt_warn.
+	* misc/sys/select.h: Added _STRICT_FD_SIZE_CHECK check.
+	* Versions.def: Added GLIBC_2.18
+	* debug/Versions: Added __fdelt_check and __fdelt_check_warn.
+	* debug/tst-chk1.c (do_test): Added _STRICT_FD_SIZE_CHECK check.
+	* debug/tst-chk7.c: New file for testing _STRICT_FD_SIZE_CHECK.
+	* debug/tst-lfschk7.c: Likewise.
+	* debug/Makefile: Added tst-chk7.c and tst-lfschk7.c.
+
+2013-03-25  KOSAKI Motohiro  <kosaki.motohiro@gmail.com>
+
 	* debug/fdelt_chk.c (__fdelt_chk): Removed range check
 	and renamed to __fdelt_nochk.
 
diff --git a/Versions.def b/Versions.def
index 3c9e0ae..8651992 100644
--- a/Versions.def
+++ b/Versions.def
@@ -34,6 +34,7 @@ libc {
   GLIBC_2.15
   GLIBC_2.16
   GLIBC_2.17
+  GLIBC_2.18
   HURD_CTHREADS_0.3
 %ifdef EXPORT_UNWIND_FIND_FDE
   GCC_3.0
diff --git a/debug/Makefile b/debug/Makefile
index 40446d4..ff53665 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -96,24 +96,28 @@ CFLAGS-tst-chk3.c = -Wno-format
 CFLAGS-tst-chk4.cc = -Wno-format
 CFLAGS-tst-chk5.cc = -Wno-format
 CFLAGS-tst-chk6.cc = -Wno-format
+CFLAGS-tst-chk7.c = -Wno-format
 CFLAGS-tst-lfschk1.c = -Wno-format
 CFLAGS-tst-lfschk2.c = -Wno-format
 CFLAGS-tst-lfschk3.c = -Wno-format
 CFLAGS-tst-lfschk4.cc = -Wno-format
 CFLAGS-tst-lfschk5.cc = -Wno-format
 CFLAGS-tst-lfschk6.cc = -Wno-format
+CFLAGS-tst-lfschk7.c = -Wno-format
 tst-chk1-ENV = LOCPATH=$(common-objpfx)localedata
 tst-chk2-ENV = LOCPATH=$(common-objpfx)localedata
 tst-chk3-ENV = LOCPATH=$(common-objpfx)localedata
 tst-chk4-ENV = LOCPATH=$(common-objpfx)localedata
 tst-chk5-ENV = LOCPATH=$(common-objpfx)localedata
 tst-chk6-ENV = LOCPATH=$(common-objpfx)localedata
+tst-chk7-ENV = LOCPATH=$(common-objpfx)localedata
 tst-lfschk1-ENV = LOCPATH=$(common-objpfx)localedata
 tst-lfschk2-ENV = LOCPATH=$(common-objpfx)localedata
 tst-lfschk3-ENV = LOCPATH=$(common-objpfx)localedata
 tst-lfschk4-ENV = LOCPATH=$(common-objpfx)localedata
 tst-lfschk5-ENV = LOCPATH=$(common-objpfx)localedata
 tst-lfschk6-ENV = LOCPATH=$(common-objpfx)localedata
+tst-lfschk7-ENV = LOCPATH=$(common-objpfx)localedata
 LDLIBS-tst-chk4 = -lstdc++
 LDLIBS-tst-chk5 = -lstdc++
 LDLIBS-tst-chk6 = -lstdc++
@@ -124,7 +128,7 @@ LDLIBS-tst-lfschk6 = -lstdc++
 tests = backtrace-tst tst-longjmp_chk tst-chk1 tst-chk2 tst-chk3 \
 	tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk \
 	tst-chk4 tst-chk5 tst-chk6 tst-lfschk4 tst-lfschk5 tst-lfschk6 \
-	tst-longjmp_chk2
+	tst-longjmp_chk2 tst-chk7 tst-lfschk7
 
 tests-ifunc := $(stpcpy_chk strcpy_chk:%=test-%-ifunc)
 tests += $(tests-ifunc)
diff --git a/debug/Versions b/debug/Versions
index c1722fa..9d7f097 100644
--- a/debug/Versions
+++ b/debug/Versions
@@ -55,6 +55,9 @@ libc {
   GLIBC_2.16 {
     __poll_chk; __ppoll_chk;
   }
+  GLIBC_2.18 {
+    __fdelt_check; __fdelt_check_warn;
+  }
   GLIBC_PRIVATE {
     __fortify_fail;
   }
diff --git a/debug/fdelt_chk.c b/debug/fdelt_chk.c
index 6588be0..67ab87e 100644
--- a/debug/fdelt_chk.c
+++ b/debug/fdelt_chk.c
@@ -25,3 +25,13 @@ __fdelt_nochk (long int d)
 }
 strong_alias (__fdelt_nochk, __fdelt_chk)
 strong_alias (__fdelt_nochk, __fdelt_warn)
+
+long int
+__fdelt_check (long int d)
+{
+  if (d < 0 || d >= FD_SETSIZE)
+    __chk_fail ();
+
+  return d / __NFDBITS;
+}
+strong_alias (__fdelt_check, __fdelt_check_warn)
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
index 6ca8d9d..4ca0596 100644
--- a/debug/tst-chk1.c
+++ b/debug/tst-chk1.c
@@ -1453,19 +1453,19 @@ do_test (void)
   fd_set s;
   FD_ZERO (&s);
   FD_SET (FD_SETSIZE - 1, &s);
-#if __USE_FORTIFY_LEVEL >= 1
+#if __USE_FORTIFY_LEVEL >= 1 && _STRICT_FD_SIZE_CHECK >= 1
   CHK_FAIL_START
   FD_SET (FD_SETSIZE, &s);
   CHK_FAIL_END
 #endif
   FD_CLR (FD_SETSIZE - 1, &s);
-#if __USE_FORTIFY_LEVEL >= 1
+#if __USE_FORTIFY_LEVEL >= 1 && _STRICT_FD_SIZE_CHECK >= 1
   CHK_FAIL_START
   FD_CLR (FD_SETSIZE, &s);
   CHK_FAIL_END
 #endif
   FD_ISSET (FD_SETSIZE - 1, &s);
-#if __USE_FORTIFY_LEVEL >= 1
+#if __USE_FORTIFY_LEVEL >= 1 && _STRICT_FD_SIZE_CHECK >= 1
   CHK_FAIL_START
   FD_ISSET (FD_SETSIZE, &s);
   CHK_FAIL_END
diff --git a/debug/tst-chk7.c b/debug/tst-chk7.c
new file mode 100644
index 0000000..9ef58f3
--- /dev/null
+++ b/debug/tst-chk7.c
@@ -0,0 +1,3 @@
+#define _FORTIFY_SOURCE 1
+#define _STRICT_FD_SIZE_CHECK 1
+#include "tst-chk1.c"
diff --git a/debug/tst-lfschk7.c b/debug/tst-lfschk7.c
new file mode 100644
index 0000000..14cc1fb
--- /dev/null
+++ b/debug/tst-lfschk7.c
@@ -0,0 +1,2 @@
+#define _FILE_OFFSET_BITS 64
+#include "tst-chk7.c"
diff --git a/misc/bits/select2.h b/misc/bits/select2.h
index 03558c9..27ad3c3 100644
--- a/misc/bits/select2.h
+++ b/misc/bits/select2.h
@@ -21,8 +21,8 @@
 #endif
 
 /* Helper functions to issue warnings and errors when needed.  */
-extern long int __fdelt_chk (long int __d);
-extern long int __fdelt_warn (long int __d)
+extern long int __fdelt_check (long int __d);
+extern long int __fdelt_check_warn (long int __d)
   __warnattr ("bit outside of fd_set selected");
 #undef __FD_ELT
 #define	__FD_ELT(d) \
@@ -31,5 +31,5 @@ extern long int __fdelt_warn (long int __d)
      (__builtin_constant_p (__d)					    \
       ? (0 <= __d && __d < __FD_SETSIZE					    \
 	 ? (__d / __NFDBITS)						    \
-	 : __fdelt_warn (__d))						    \
-      : __fdelt_chk (__d)); })
+	 : __fdelt_check_warn (__d))					    \
+      : __fdelt_check (__d)); })
diff --git a/misc/sys/select.h b/misc/sys/select.h
index 21351fe..6a6dce6 100644
--- a/misc/sys/select.h
+++ b/misc/sys/select.h
@@ -124,7 +124,7 @@ extern int pselect (int __nfds, fd_set *__restrict __readfds,
 
 
 /* Define some inlines helping to catch common problems.  */
-#if __USE_FORTIFY_LEVEL > 0 && defined __GNUC__
+#if __USE_FORTIFY_LEVEL > 0 && defined __GNUC__ && _STRICT_FD_SIZE_CHECK > 0
 # include <bits/select2.h>
 #endif
 
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]