aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--debug/Makefile2
-rw-r--r--debug/Versions2
-rw-r--r--debug/confstr_chk.c30
-rw-r--r--debug/getdomainname_chk.c29
-rw-r--r--debug/getgroups_chk.c30
-rw-r--r--debug/gethostname_chk.c29
-rw-r--r--debug/getlogin_r_chk.c29
-rw-r--r--debug/tst-chk1.c68
-rw-r--r--debug/ttyname_r_chk.c29
-rw-r--r--nscd/grpcache.c2
-rw-r--r--posix/bits/unistd.h98
12 files changed, 366 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index a4c84f7..8233e5f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,24 @@
+2005-07-18 Ulrich Drepper <drepper@redhat.com>
+
+ * nscd/grpcache.c (cache_addgr): Use correct maximum for group ID
+ length. Patch by Ivan Gyurdiev <ivg2@cornell.edu>.
+
+ * debug/confstr_chk.c: New file.
+ * debug/getdomainname_chk.c: New file.
+ * debug/getgroups_chk.c: New file.
+ * debug/gethostname_chk.c: New file.
+ * debug/getlogin_r_chk.c: New file.
+ * debug/ttyname_r_chk.c: New file.
+ * posix/bits/unistd.h: Add definitions for new debug versions.
+ * debug/tst-chk1.c: Add tests for new functions.
+ * debug/Versions: Export new functions.
+ * debug/Makefile (routines): Add new files.
+
+ * stdlib/bits/stdlib.h: Fix typo.
+
2005-07-13 Thorsten Kukuk <kukuk@suse.de>
- * manual/Makefile (libc/index.html): Depend on dir-add.texi.
+ * manual/Makefile (libc/index.html): Depend on dir-add.texi.
2005-07-15 Ulrich Drepper <drepper@redhat.com>
diff --git a/debug/Makefile b/debug/Makefile
index 879764a..e3fccc1 100644
--- a/debug/Makefile
+++ b/debug/Makefile
@@ -37,6 +37,8 @@ routines = backtrace backtracesyms backtracesymsfd noophooks \
wcpncpy_chk \
swprintf_chk vswprintf_chk wprintf_chk fwprintf_chk \
vwprintf_chk vfwprintf_chk fgetws_chk fgetws_u_chk \
+ confstr_chk getgroups_chk ttyname_r_chk getlogin_r_chk \
+ gethostname_chk getdomainname_chk \
stack_chk_fail \
$(static-only-routines)
static-only-routines := warning-nop stack_chk_fail_local
diff --git a/debug/Versions b/debug/Versions
index 0953c77..f33fbed 100644
--- a/debug/Versions
+++ b/debug/Versions
@@ -29,6 +29,8 @@ libc {
__wcsncpy_chk; __wcscat_chk; __wcsncat_chk; __wmemset_chk; __wcpncpy_chk;
__swprintf_chk; __vswprintf_chk; __wprintf_chk; __fwprintf_chk;
__vwprintf_chk; __vfwprintf_chk; __fgetws_chk; __fgetws_unlocked_chk;
+ __confstr_chk; __getgroups_chk; __ttyname_r_chk; __getlogin_r_chk;
+ __gethostname_chk; __getdomainname_chk;
__stack_chk_fail;
}
diff --git a/debug/confstr_chk.c b/debug/confstr_chk.c
new file mode 100644
index 0000000..dae7714
--- /dev/null
+++ b/debug/confstr_chk.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@readhat.com>, 20055.
+
+ 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 <unistd.h>
+
+
+size_t
+__confstr_chk (int name, char *buf, size_t len, size_t buflen)
+{
+ if (__builtin_expect (buflen < len, 0))
+ __chk_fail ();
+
+ return confstr (name, buf, len);
+}
diff --git a/debug/getdomainname_chk.c b/debug/getdomainname_chk.c
new file mode 100644
index 0000000..a854645
--- /dev/null
+++ b/debug/getdomainname_chk.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2005 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 <unistd.h>
+
+
+int
+__getdomainname_chk (char *buf, size_t buflen, size_t nreal)
+{
+ if (buflen > nreal)
+ __chk_fail ();
+
+ return getdomainname (buf, buflen);
+}
diff --git a/debug/getgroups_chk.c b/debug/getgroups_chk.c
new file mode 100644
index 0000000..6401b02
--- /dev/null
+++ b/debug/getgroups_chk.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2005 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 <errno.h>
+#include <unistd.h>
+
+
+char *
+__getgroups_chk (int size, __gid_t list[], size_t listlen)
+{
+ if (__builtin_expect (size * sizeof (__gid_t) > listlen, 0))
+ __chk_fail ();
+
+ return __getgroups (size, list);
+}
diff --git a/debug/gethostname_chk.c b/debug/gethostname_chk.c
new file mode 100644
index 0000000..734cc56
--- /dev/null
+++ b/debug/gethostname_chk.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2005 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 <unistd.h>
+
+
+int
+__gethostname_chk (char *buf, size_t buflen, size_t nreal)
+{
+ if (buflen > nreal)
+ __chk_fail ();
+
+ return __gethostname (buf, buflen);
+}
diff --git a/debug/getlogin_r_chk.c b/debug/getlogin_r_chk.c
new file mode 100644
index 0000000..ae495cd
--- /dev/null
+++ b/debug/getlogin_r_chk.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2005 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 <unistd.h>
+
+
+int
+__getlogin_r_chk (char *buf, size_t buflen, size_t nreal)
+{
+ if (buflen > nreal)
+ __chk_fail ();
+
+ return getlogin_r (buf, buflen);
+}
diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c
index a83bd84..47938bb 100644
--- a/debug/tst-chk1.c
+++ b/debug/tst-chk1.c
@@ -1083,7 +1083,75 @@ do_test (void)
}
CHK_FAIL_END
#endif
+ close (fd);
+ }
+
+ confstr (_CS_GNU_LIBC_VERSION, largebuf, sizeof (largebuf));
+#if __USE_FORTIFY_LEVEL >= 1
+ CHK_FAIL_START
+ char smallbuf[1];
+ confstr (_CS_GNU_LIBC_VERSION, smallbuf, sizeof (largebuf));
+ CHK_FAIL_END
+#endif
+
+ gid_t grpslarge[5];
+ int ngr = getgroups (5, grpslarge);
+#if __USE_FORTIFY_LEVEL >= 1
+ CHK_FAIL_START
+ char smallbuf[1];
+ ngr = getgroups (5, (gid_t *) smallbuf);
+ CHK_FAIL_END
+#endif
+
+ fd = open (_PATH_TTY, O_RDONLY);
+ if (fd != -1)
+ {
+ char enough[1000];
+ if (ttyname_r (fd, enough, sizeof (enough)) != 0)
+ {
+ puts ("first ttyname_r failed");
+ ret = 1;
+ }
+
+#if __USE_FORTIFY_LEVEL >= 1
+ CHK_FAIL_START
+ char smallbuf[2];
+ if (ttyname_r (fd, smallbuf, sizeof (smallbuf) + 1) == 0)
+ {
+ puts ("second ttyname_r somehow suceeded");
+ ret = 1;
+ }
+ CHK_FAIL_END
+#endif
+ close (fd);
}
+ char hostnamelarge[1000];
+ gethostname (hostnamelarge, sizeof (hostnamelarge));
+#if __USE_FORTIFY_LEVEL >= 1
+ CHK_FAIL_START
+ char smallbuf[1];
+ gethostname (smallbuf, sizeof (hostnamelarge));
+ CHK_FAIL_END
+#endif
+
+ char loginlarge[1000];
+ getlogin_r (loginlarge, sizeof (hostnamelarge));
+#if __USE_FORTIFY_LEVEL >= 1
+ CHK_FAIL_START
+ char smallbuf[1];
+ getlogin_r (smallbuf, sizeof (loginlarge));
+ CHK_FAIL_END
+#endif
+
+ char domainnamelarge[1000];
+ int res = getdomainname (domainnamelarge, sizeof (domainnamelarge));
+#if __USE_FORTIFY_LEVEL >= 1
+ CHK_FAIL_START
+ char smallbuf[1];
+ res = getdomainname (smallbuf, sizeof (domainnamelarge));
+ CHK_FAIL_END
+#endif
+
return ret;
}
diff --git a/debug/ttyname_r_chk.c b/debug/ttyname_r_chk.c
new file mode 100644
index 0000000..9b06d5a
--- /dev/null
+++ b/debug/ttyname_r_chk.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2005 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 <unistd.h>
+
+
+int
+__ttyname_r_chk (int fd, char *buf, size_t buflen, size_t nreal)
+{
+ if (buflen > nreal)
+ __chk_fail ();
+
+ return __ttyname_r (fd, buf, buflen);
+}
diff --git a/nscd/grpcache.c b/nscd/grpcache.c
index 5d327f3..c938554 100644
--- a/nscd/grpcache.c
+++ b/nscd/grpcache.c
@@ -167,7 +167,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
char *gr_name;
char *cp;
const size_t key_len = strlen (key);
- const size_t buf_len = 3 + sizeof (grp->gr_gid) + key_len + 1;
+ const size_t buf_len = 3 * sizeof (grp->gr_gid) + key_len + 1;
char *buf = alloca (buf_len);
ssize_t n;
size_t cnt;
diff --git a/posix/bits/unistd.h b/posix/bits/unistd.h
index cb82818..b6c756a 100644
--- a/posix/bits/unistd.h
+++ b/posix/bits/unistd.h
@@ -128,3 +128,101 @@ __NTH (getwd (char *__buf))
return __getwd_alias (__buf);
}
#endif
+
+extern size_t __confstr_chk (int __name, char *__buf, size_t __len,
+ size_t __buflen) __THROW;
+extern size_t __REDIRECT_NTH (__confstr_alias, (int __name, char *__buf,
+ size_t __len), confstr);
+
+extern __always_inline size_t
+confstr (int __name, char *__buf, size_t __len)
+{
+ if (__bos (__buf) != (size_t) -1
+ && (!__builtin_constant_p (__len) || __bos (__buf) < __len))
+ return __confstr_chk (__name, __buf, __len, __bos (__buf));
+ return __confstr_alias (__name, __buf, __len);
+}
+
+
+extern int __getgroups_chk (int __size, __gid_t __list[], size_t listlen)
+ __THROW __wur;
+extern int __REDIRECT_NTH (__getgroups_alias, (int __size, __gid_t __list[]),
+ getgroups) __wur;
+
+extern __always_inline int
+getgroups (int __size, __gid_t __list[])
+{
+ if (__bos (__list) != (size_t) -1
+ && (!__builtin_constant_p (__size)
+ || __size * sizeof (__gid_t) > __bos (__list)))
+ return __getgroups_chk (__size, __list, __bos (__list));
+ return __getgroups_alias (__size, __list);
+}
+
+
+extern int __ttyname_r_chk (int __fd, char *__buf, size_t __buflen,
+ size_t __nreal) __THROW __nonnull ((2));
+extern int __REDIRECT_NTH (__ttyname_r_alias, (int __fd, char *__buf,
+ size_t __buflen), ttyname_r)
+ __nonnull ((2));
+
+extern __always_inline int
+ttyname_r (int __fd, char *__buf, size_t __buflen)
+{
+ if (__bos (__buf) != (size_t) -1
+ && (!__builtin_constant_p (__buflen) || __buflen > __bos (__buf)))
+ return __ttyname_r_chk (__fd, __buf, __buflen, __bos (__buf));
+ return __ttyname_r_alias (__fd, __buf, __buflen);
+}
+
+
+#if defined __USE_REENTRANT || defined __USE_UNIX98
+extern int __getlogin_r_chk (char *__buf, size_t __buflen, size_t __nreal)
+ __nonnull ((1));
+extern int __REDIRECT (__getlogin_r_alias, (char *__buf, size_t __buflen),
+ getlogin_r) __nonnull ((1));
+
+extern __always_inline int
+getlogin_r (char *__buf, size_t __buflen)
+{
+ if (__bos (__buf) != (size_t) -1
+ && (!__builtin_constant_p (__buflen) || __buflen > __bos (__buf)))
+ return __getlogin_r_chk (__buf, __buflen, __bos (__buf));
+ return __getlogin_r_alias (__buf, __buflen);
+}
+#endif
+
+
+#if defined __USE_BSD || defined __USE_UNIX98
+extern int __gethostname_chk (char *__buf, size_t __buflen, size_t __nreal)
+ __THROW __nonnull ((1));
+extern int __REDIRECT_NTH (__gethostname_alias, (char *__buf, size_t __buflen),
+ gethostname) __nonnull ((1));
+
+extern __always_inline int
+gethostname (char *__buf, size_t __buflen)
+{
+ if (__bos (__buf) != (size_t) -1
+ && (!__builtin_constant_p (__buflen) || __buflen > __bos (__buf)))
+ return __gethostname_chk (__buf, __buflen, __bos (__buf));
+ return __gethostname_alias (__buf, __buflen);
+}
+#endif
+
+
+#if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
+extern int __getdomainname_chk (char *__buf, size_t __buflen, size_t __nreal)
+ __THROW __nonnull ((1)) __wur;
+extern int __REDIRECT_NTH (__getdomainname_alias, (char *__buf,
+ size_t __buflen),
+ getdomainname) __nonnull ((1)) __wur;
+
+extern __always_inline int
+getdomainname (char *__buf, size_t __buflen)
+{
+ if (__bos (__buf) != (size_t) -1
+ && (!__builtin_constant_p (__buflen) || __buflen > __bos (__buf)))
+ return __getdomainname_chk (__buf, __buflen, __bos (__buf));
+ return __getdomainname_alias (__buf, __buflen);
+}
+#endif