aboutsummaryrefslogtreecommitdiff
path: root/debug
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2011-09-08 19:48:47 -0400
committerUlrich Drepper <drepper@gmail.com>2011-09-08 19:48:47 -0400
commita0f33f996f7986dbf37631a4577f8565b42df29e (patch)
tree78c71a736d4bd75009abba7796f0e0aca78e47ec /debug
parent762011fe9ffded81448be4dc50a2b27faaafe4c9 (diff)
downloadglibc-a0f33f996f7986dbf37631a4577f8565b42df29e.tar
glibc-a0f33f996f7986dbf37631a4577f8565b42df29e.tar.gz
glibc-a0f33f996f7986dbf37631a4577f8565b42df29e.tar.bz2
glibc-a0f33f996f7986dbf37631a4577f8565b42df29e.zip
Add range checking for FD_SET, FD_CLR, and FD_ISSET
Diffstat (limited to 'debug')
-rw-r--r--debug/Makefile3
-rw-r--r--debug/Versions3
-rw-r--r--debug/fdelt_chk.c30
-rw-r--r--debug/tst-chk1.c32
4 files changed, 62 insertions, 6 deletions
diff --git a/debug/Makefile b/debug/Makefile
index d7c51ca85f..e6842f0ae5 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1998-2001,2004-2008, 2009 Free Software Foundation, Inc.
+# Copyright (C) 1998-2001,2004-2008, 2009, 2011 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -44,6 +44,7 @@ routines = backtrace backtracesyms backtracesymsfd noophooks \
wcstombs_chk asprintf_chk vasprintf_chk dprintf_chk \
vdprintf_chk obprintf_chk \
longjmp_chk ____longjmp_chk \
+ fdelt_chk \
stack_chk_fail fortify_fail \
$(static-only-routines)
static-only-routines := warning-nop stack_chk_fail_local
diff --git a/debug/Versions b/debug/Versions
index ff40107b77..3db4a2955f 100644
--- a/debug/Versions
+++ b/debug/Versions
@@ -49,6 +49,9 @@ libc {
GLIBC_2.11 {
__longjmp_chk;
}
+ GLIBC_2.15 {
+ __fdelt_chk; __fdelt_warn;
+ }
GLIBC_PRIVATE {
__fortify_fail;
}
diff --git a/debug/fdelt_chk.c b/debug/fdelt_chk.c
new file mode 100644
index 0000000000..7d9e4b96e8
--- /dev/null
+++ b/debug/fdelt_chk.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2011 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <sys/select.h>
+
+
+unsigned long int
+__fdelt_chk (unsigned long int d)
+{
+ if (d >= FD_SETSIZE)
+ __chk_fail ();
+
+ return d / __NFDBITS;
+}
+strong_alias (__fdelt_chk, __fdelt_warn)
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
index e03f3dba6d..0ec8ab07d9 100644
--- a/debug/tst-chk1.c
+++ b/debug/tst-chk1.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 2004,2005,2006,2007,2008,2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
@@ -29,6 +29,7 @@
#include <string.h>
#include <unistd.h>
#include <wchar.h>
+#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -107,11 +108,11 @@ int num2 = 987654;
FAIL (); \
}
#if __USE_FORTIFY_LEVEL >= 2 && (!defined __cplusplus || defined __va_arg_pack)
-#define CHK_FAIL2_START CHK_FAIL_START
-#define CHK_FAIL2_END CHK_FAIL_END
+# define CHK_FAIL2_START CHK_FAIL_START
+# define CHK_FAIL2_END CHK_FAIL_END
#else
-#define CHK_FAIL2_START
-#define CHK_FAIL2_END
+# define CHK_FAIL2_START
+# define CHK_FAIL2_END
#endif
static int
@@ -1448,5 +1449,26 @@ do_test (void)
CHK_FAIL_END
#endif
+ fd_set s;
+ FD_ZERO (&s);
+ FD_SET (FD_SETSIZE - 1, &s);
+#if __USE_FORTIFY_LEVEL >= 1
+ CHK_FAIL_START
+ FD_SET (FD_SETSIZE, &s);
+ CHK_FAIL_END
+#endif
+ FD_CLR (FD_SETSIZE - 1, &s);
+#if __USE_FORTIFY_LEVEL >= 1
+ CHK_FAIL_START
+ FD_CLR (FD_SETSIZE, &s);
+ CHK_FAIL_END
+#endif
+ FD_ISSET (FD_SETSIZE - 1, &s);
+#if __USE_FORTIFY_LEVEL >= 1
+ CHK_FAIL_START
+ FD_ISSET (FD_SETSIZE, &s);
+ CHK_FAIL_END
+#endif
+
return ret;
}