mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-08 17:42:12 +03:00
* 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.
This commit is contained in:
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
30
debug/confstr_chk.c
Normal file
30
debug/confstr_chk.c
Normal file
@@ -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);
|
||||
}
|
29
debug/getdomainname_chk.c
Normal file
29
debug/getdomainname_chk.c
Normal file
@@ -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);
|
||||
}
|
30
debug/getgroups_chk.c
Normal file
30
debug/getgroups_chk.c
Normal file
@@ -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);
|
||||
}
|
29
debug/gethostname_chk.c
Normal file
29
debug/gethostname_chk.c
Normal file
@@ -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);
|
||||
}
|
29
debug/getlogin_r_chk.c
Normal file
29
debug/getlogin_r_chk.c
Normal file
@@ -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);
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
29
debug/ttyname_r_chk.c
Normal file
29
debug/ttyname_r_chk.c
Normal file
@@ -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);
|
||||
}
|
Reference in New Issue
Block a user