diff options
author | Ulrich Drepper <drepper@redhat.com> | 2005-07-18 21:07:28 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2005-07-18 21:07:28 +0000 |
commit | 9f3731cf7f8f1d1b4718fdbeae2ca5d46bbc6950 (patch) | |
tree | 1cbff2cd7ef38c777aa3a6c713b1513e038f2483 /debug | |
parent | 0396de518e3ed6b4bebea10026ca5c7aaafa783f (diff) | |
download | glibc-9f3731cf7f8f1d1b4718fdbeae2ca5d46bbc6950.tar.gz glibc-9f3731cf7f8f1d1b4718fdbeae2ca5d46bbc6950.tar.xz glibc-9f3731cf7f8f1d1b4718fdbeae2ca5d46bbc6950.zip |
* 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. * manual/Makefile (libc/index.html): Depend on dir-add.texi.
Diffstat (limited to 'debug')
-rw-r--r-- | debug/Makefile | 2 | ||||
-rw-r--r-- | debug/Versions | 2 | ||||
-rw-r--r-- | debug/confstr_chk.c | 30 | ||||
-rw-r--r-- | debug/getdomainname_chk.c | 29 | ||||
-rw-r--r-- | debug/getgroups_chk.c | 30 | ||||
-rw-r--r-- | debug/gethostname_chk.c | 29 | ||||
-rw-r--r-- | debug/getlogin_r_chk.c | 29 | ||||
-rw-r--r-- | debug/tst-chk1.c | 68 | ||||
-rw-r--r-- | debug/ttyname_r_chk.c | 29 |
9 files changed, 248 insertions, 0 deletions
diff --git a/debug/Makefile b/debug/Makefile index 879764a495..e3fccc192e 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 0953c7733b..f33fbed6ef 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 0000000000..dae7714fcf --- /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 0000000000..a85464589b --- /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 0000000000..6401b023d3 --- /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 0000000000..734cc56b0b --- /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 0000000000..ae495cd7ab --- /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 a83bd843c6..47938bbf36 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 0000000000..9b06d5a718 --- /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); +} |