diff options
author | Ulrich Drepper <drepper@redhat.com> | 2006-04-24 17:01:40 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2006-04-24 17:01:40 +0000 |
commit | a346370d582ed9be5e434f955c049e75abc37c28 (patch) | |
tree | d3bf31f79d210adfa9b58a906afe65237b879ae1 /debug | |
parent | 34a15e61e019c0aaa6b56c79b75ddb0ded49f590 (diff) | |
download | glibc-a346370d582ed9be5e434f955c049e75abc37c28.zip glibc-a346370d582ed9be5e434f955c049e75abc37c28.tar.gz glibc-a346370d582ed9be5e434f955c049e75abc37c28.tar.bz2 |
* posix/bits/unistd.h (__readlinkat_chk): New prototype.
(__readlinkat_alias): New alias.
(readlinkat): New inline function.
* include/unistd.h (readlinkat): Add libc_hidden_proto.
* sysdeps/unix/sysv/linux/readlinkat.c (readlinkat): Add
libc_hidden_def.
* io/readlinkat.c (readlinkat): Likewise.
* debug/readlinkat_chk.c: New file.
* debug/Makefile (routines): Add readlinkat_chk.
* debug/Versions (libc): Export __readlinkat_chk@@GLIBC_2.5.
* debug/tst-chk1.c (do_test): Add readlinkat tests.
* nis/nss_nisplus/nisplus-netgrp.c: Cleanups.
code is possible. Move compatibility code in .text.compat section.
over gaih array. There is only one function to call in the moment.
Diffstat (limited to 'debug')
-rw-r--r-- | debug/Makefile | 3 | ||||
-rw-r--r-- | debug/Versions | 3 | ||||
-rw-r--r-- | debug/readlinkat_chk.c | 31 | ||||
-rw-r--r-- | debug/tst-chk1.c | 30 |
4 files changed, 65 insertions, 2 deletions
diff --git a/debug/Makefile b/debug/Makefile index 9123bf6..4b4b541 100644 --- a/debug/Makefile +++ b/debug/Makefile @@ -31,7 +31,8 @@ routines = backtrace backtracesyms backtracesymsfd noophooks \ printf_chk fprintf_chk vprintf_chk vfprintf_chk \ gets_chk chk_fail readonly-area fgets_chk fgets_u_chk \ read_chk pread_chk pread64_chk recv_chk recvfrom_chk \ - readlink_chk getwd_chk getcwd_chk realpath_chk ptsname_r_chk \ + readlink_chk readlinkat_chk getwd_chk getcwd_chk \ + realpath_chk ptsname_r_chk \ wctomb_chk wcscpy_chk wmemcpy_chk wmemmove_chk wmempcpy_chk \ wcpcpy_chk wcsncpy_chk wcscat_chk wcsncat_chk wmemset_chk \ wcpncpy_chk \ diff --git a/debug/Versions b/debug/Versions index 683eb17..5c87af2 100644 --- a/debug/Versions +++ b/debug/Versions @@ -36,4 +36,7 @@ libc { __stack_chk_fail; } + GLIBC_2.5 { + __readlinkat_chk; + } } diff --git a/debug/readlinkat_chk.c b/debug/readlinkat_chk.c new file mode 100644 index 0000000..eab99c0 --- /dev/null +++ b/debug/readlinkat_chk.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2006 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> +#include <sys/param.h> + + +ssize_t +__readlinkat_chk (int fd, const char *path, void *buf, size_t len, + size_t buflen) +{ + if (len > buflen) + __chk_fail (); + + return readlinkat (fd, path, buf, len); +} diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c index ee080ce..993dab6 100644 --- a/debug/tst-chk1.c +++ b/debug/tst-chk1.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2004, 2005 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2004. @@ -944,6 +944,34 @@ do_test (void) CHK_FAIL_END #endif + int tmpfd = open ("/tmp", O_RDONLY | O_DIRECTORY); + if (tmpfd < 0) + FAIL (); + + if (readlinkat (tmpfd, fname + sizeof ("/tmp/") - 1, readlinkbuf, 4) != 3 + || memcmp (readlinkbuf, "bar", 3) != 0) + FAIL (); + if (readlinkat (tmpfd, fname + sizeof ("/tmp/") - 1, readlinkbuf + 1, + l0 + 3) != 3 + || memcmp (readlinkbuf, "bbar", 4) != 0) + FAIL (); + +#if __USE_FORTIFY_LEVEL >= 1 + CHK_FAIL_START + if (readlinkat (tmpfd, fname + sizeof ("/tmp/") - 1, readlinkbuf + 2, + l0 + 3) != 3) + FAIL (); + CHK_FAIL_END + + CHK_FAIL_START + if (readlinkat (tmpfd, fname + sizeof ("/tmp/") - 1, readlinkbuf + 3, + 4) != 3) + FAIL (); + CHK_FAIL_END +#endif + + close (tmpfd); + char *cwd1 = getcwd (NULL, 0); if (cwd1 == NULL) FAIL (); |