This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use extern inline wrappers instead of macros for some checking functions


Hi!

This patch:
a) fixes getwd, pread and pread64 that were broken before
b) starts using extern inline wrappers instead of macros for those checking
   routines that have no GCC builtins.  Although programs using say
   somestruct->read (buf, 1, 2, 3);
   without #undef read or using (somestruct->read) (buf, 1, 2, 3);
   are broken, there are simply too many of them.
   The wrappers for routines that have checking builtins in GCC
   (like memcpy, strcpy or e.g. printf) should stay as is, so that warnings
   about them are reported on the place where the bug occurs instead of
   always in say bits/string3.h.
c) improves test coverage of these functions
Tested with GCC 4.0-RH with:
-#if _FORTIFY_SOURCE > 0 && __GNUC_PREREQ (4, 1) && __OPTIMIZE__ > 0
+#if _FORTIFY_SOURCE > 0 && (__GNUC_PREREQ (4, 1) || (defined __GNUC_RH_RELEASE__ && __GNUC_PREREQ (4, 0))) && __OPTIMIZE__ > 0
so that tst-chk{2,3} actually test something.

2005-03-09  Jakub Jelinek  <jakub@redhat.com>

	* debug/tst-chk1.c: Include sys/socket.h and sys/un.h.
	(do_test): Add new tests for recv, recvfrom, getcwd, getwd and
	readlink.  Add some more tests for read, pread, pread64, fgets and
	fgets_unlocked.

	* posix/bits/unistd.h (read, pread, pread64, readlink,
	getcwd, getwd): Change macros into extern inline functions.
	(__read_alias, __pread_alias, __pread64_alias, __readlink_alias,
	__getcwd_alias, __getwd_alias): New prototypes.
	* socket/bits/socket2.h (recv, recvfrom): Change macros into
	extern inline functions.
	(__recv_alias, __recvfrom_alias): New prototypes.
	* libio/bits/stdio2.h (gets, fgets, fgets_unlocked): Change macros
	into extern inline functions.
	(__gets_alias, __fgets_alias, __fgets_unlocked_alias): New prototypes.

	* debug/pread_chk.c (__pread_chk): Fix order of arguments passed
	to __pread.
	* debug/pread64_chk.c (__pread64_chk): Fix order of arguments passed
	to __pread64.

--- libc/posix/bits/unistd.h.jj	2005-03-08 13:07:57.000000000 +0100
+++ libc/posix/bits/unistd.h	2005-03-09 18:22:08.072720104 +0100
@@ -23,37 +23,58 @@
 
 extern ssize_t __read_chk (int __fd, void *__buf, size_t __nbytes,
 			   size_t __buflen) __wur;
-#define read(fd, buf, nbytes) \
-  (__bos0 (buf) != (size_t) -1						      \
-   && (!__builtin_constant_p (nbytes) || (nbytes) > __bos0 (buf))	      \
-   ? __read_chk (fd, buf, nbytes, __bos0 (buf))				      \
-   : read (fd, buf, nbytes))
+extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf,
+					  size_t __nbytes), read) __wur;
+
+extern __inline __wur ssize_t
+read (int __fd, void *__buf, size_t __nbytes)
+{
+  if (__bos0 (__buf) != (size_t) -1
+      && (!__builtin_constant_p (__nbytes) || __nbytes > __bos0 (__buf)))
+    return __read_chk (__fd, __buf, __nbytes, __bos0 (__buf));
+  return __read_alias (__fd, __buf, __nbytes);
+}
 
 #ifdef __USE_UNIX98
 extern ssize_t __pread_chk (int __fd, void *__buf, size_t __nbytes,
 			    __off_t __offset, size_t __bufsize) __wur;
 extern ssize_t __pread64_chk (int __fd, void *__buf, size_t __nbytes,
 			      __off64_t __offset, size_t __bufsize) __wur;
+extern ssize_t __REDIRECT (__pread_alias,
+			   (int __fd, void *__buf, size_t __nbytes,
+			    __off_t __offset), pread) __wur;
+extern ssize_t __REDIRECT (__pread64_alias,
+			   (int __fd, void *__buf, size_t __nbytes,
+			    __off64_t __offset), pread64) __wur;
 # ifndef __USE_FILE_OFFSET64
-#  define pread(fd, buf, nbytes, offset) \
-  (__bos0 (buf) != (size_t) -1						      \
-   && (!__builtin_constant_p (nbytes) || (nbytes) > __bos0 (buf))	      \
-   ? __pread64_chk (fd, buf, nbytes, offset, __bos0 (buf))		      \
-   : pread64 (fd, buf, nbytes, offset))
+extern __inline __wur ssize_t
+pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset)
+{
+  if (__bos0 (__buf) != (size_t) -1
+      && (!__builtin_constant_p (__nbytes) || __nbytes > __bos0 (__buf)))
+    return __pread_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
+  return __pread_alias (__fd, __buf, __nbytes, __offset);
+}
 # else
-#  define pread(fd, buf, nbytes, offset) \
-  (__bos0 (buf) != (size_t) -1						      \
-   && (!__builtin_constant_p (nbytes) || (nbytes) > __bos0 (buf))	      \
-   ? __pread_chk (fd, buf, nbytes, offset, __bos0 (buf))		      \
-   : pread (fd, buf, nbytes, offset))
+extern __inline __wur ssize_t
+pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset)
+{
+  if (__bos0 (__buf) != (size_t) -1
+      && (!__builtin_constant_p (__nbytes) || __nbytes > __bos0 (__buf)))
+    return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
+  return __pread64_alias (__fd, __buf, __nbytes, __offset);
+}
 # endif
 
 # ifdef __USE_LARGEFILE64
-#  define pread64(fd, buf, nbytes, offset) \
-  (__bos0 (buf) != (size_t) -1						      \
-   && (!__builtin_constant_p (nbytes) || (nbytes) > __bos0 (buf))	      \
-   ? __pread64_chk (fd, buf, nbytes, offset, __bos0 (buf))		      \
-   : pread64 (fd, buf, nbytes, offset))
+extern __inline __wur ssize_t
+pread64 (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
+{
+  if (__bos0 (__buf) != (size_t) -1
+      && (!__builtin_constant_p (__nbytes) || __nbytes > __bos0 (__buf)))
+    return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
+  return __pread64_alias (__fd, __buf, __nbytes, __offset);
+}
 # endif
 #endif
 
@@ -62,23 +83,44 @@ extern int __readlink_chk (__const char 
 			   char *__restrict __buf, size_t __len,
 			   size_t __buflen)
      __THROW __nonnull ((1, 2)) __wur;
-# define readlink(path, buf, len) \
-  (__bos (buf) != (size_t) -1						      \
-   && (!__builtin_constant_p (len) || (len) > __bos (buf))		      \
-   ? __readlink_chk (path, buf, len, __bos (buf))			      \
-   : readlink (path, buf, len))
+extern int __REDIRECT_NTH (__readlink_alias,
+			   (__const char *__restrict __path,
+			    char *__restrict __buf, size_t __len), readlink)
+     __nonnull ((1, 2)) __wur;
+extern __inline __nonnull ((1, 2)) __wur int
+__NTH (readlink (__const char *__restrict __path, char *__restrict __buf,
+		 size_t __len))
+{
+  if (__bos (__buf) != (size_t) -1
+      && (!__builtin_constant_p (__len) || __len > __bos (__buf)))
+    return __readlink_chk (__path, __buf, __len, __bos (__buf));
+  return __readlink_alias (__path, __buf, __len);
+}
 #endif
 
 extern char *__getcwd_chk (char *__buf, size_t __size, size_t __buflen)
      __THROW __wur;
-#define getcwd(buf, size) \
-  (__bos (buf) != (size_t) -1						      \
-   && (!__builtin_constant_p (size) || (size) > __bos (buf))		      \
-   ? __getcwd_chk (buf, size, buflen) : getcwd (buf, size))
+extern char *__REDIRECT_NTH (__getcwd_alias,
+			     (char *__buf, size_t __size), getcwd) __wur;
+extern __inline __wur char *
+__NTH (getcwd (char *__buf, size_t __size))
+{
+  if (__bos (__buf) != (size_t) -1
+      && (!__builtin_constant_p (__size) || __size > __bos (__buf)))
+    return __getcwd_chk (__buf, __size, __bos (__buf));
+  return __getcwd_alias (__buf, __size);
+}
 
 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
 extern char *__getwd_chk (char *__buf, size_t buflen)
-     __THROW __nonnull ((1)) __attribute_deprecated__ __wur;
-#define getwd(buf) \
-  (__bos (buf) != (size_t) -1 ? __getwd_chk (buf, buflen) : getwd (buf))
+     __THROW __nonnull ((1)) __wur;
+extern char *__REDIRECT_NTH (__getwd_alias, (char *__buf), getwd)
+     __nonnull ((1)) __wur;
+extern __inline __nonnull ((1)) __attribute_deprecated__ __wur char *
+__NTH (getwd (char *__buf))
+{
+  if (__bos (__buf) != (size_t) -1)
+    return __getwd_chk (__buf, __bos (__buf));
+  return __getwd_alias (__buf);
+}
 #endif
--- libc/socket/bits/socket2.h.jj	2005-03-08 13:05:19.000000000 +0100
+++ libc/socket/bits/socket2.h	2005-03-09 19:26:39.630161924 +0100
@@ -23,18 +23,34 @@
 
 extern ssize_t __recv_chk (int __fd, void *__buf, size_t __n, size_t __buflen,
 			   int __flags);
-#define recv(fd, buf, n, flags) \
-  (__bos0 (buf) != (size_t) -1						      \
-   && (!__builtin_constant_p (n) || (n) > __bos0 (buf))			      \
-   ? __recv_chk (fd, buf, n, __bos0 (buf), flags)			      \
-   : recv (fd, buf, n, flags))
+extern ssize_t __REDIRECT (__recv_alias, (int __fd, void *__buf, size_t __n,
+					  int __flags), recv);
+
+extern __inline ssize_t
+recv (int __fd, void *__buf, size_t __n, int __flags)
+{
+  if (__bos0 (__buf) != (size_t) -1
+      && (!__builtin_constant_p (__n) || __n > __bos0 (__buf)))
+    return __recv_chk (__fd, __buf, __n, __bos0 (__buf), __flags);
+  return __recv_alias (__fd, __buf, __n, __flags);
+}
 
 extern ssize_t __recvfrom_chk (int __fd, void *__restrict __buf, size_t __n,
 			       size_t __buflen, int __flags,
 			       __SOCKADDR_ARG __addr,
 			       socklen_t *__restrict __addr_len);
-#define recvfrom(fd, buf, n, flags, addr, addr_len) \
-  (__bos0 (buf) != (size_t) -1						      \
-   && (!__builtin_constant_p (n) || (n) > __bos0 (buf))			      \
-   ? __recvfrom_chk (fd, buf, n, __bos0 (buf), flags, addr, addr_len)	      \
-   : recvfrom (fd, buf, n, flags, addr, addr_len))
+extern ssize_t __REDIRECT (__recvfrom_alias,
+			   (int __fd, void *__restrict __buf, size_t __n,
+			    int __flags, __SOCKADDR_ARG __addr,
+			    socklen_t *__restrict __addr_len), recvfrom);
+
+extern __inline ssize_t
+recvfrom (int __fd, void *__buf, size_t __n, int __flags,
+	  __SOCKADDR_ARG __addr, socklen_t *__restrict __addr_len)
+{
+  if (__bos0 (__buf) != (size_t) -1
+      && (!__builtin_constant_p (__n) || __n > __bos0 (__buf)))
+    return __recvfrom_chk (__fd, __buf, __n, __bos0 (__buf), __flags,
+			   __addr, __addr_len);
+  return __recvfrom_alias (__fd, __buf, __n, __flags, __addr, __addr_len);
+}
--- libc/debug/pread_chk.c.jj	2005-03-01 10:34:26.000000000 +0100
+++ libc/debug/pread_chk.c	2005-03-09 17:12:03.744371421 +0100
@@ -26,5 +26,5 @@ __pread_chk (int fd, void *buf, size_t n
   if (nbytes > buflen)
     __chk_fail ();
 
-  return __pread (fd, buf, offset, nbytes);
+  return __pread (fd, buf, nbytes, offset);
 }
--- libc/debug/tst-chk1.c.jj	2005-02-22 10:02:13.000000000 +0100
+++ libc/debug/tst-chk1.c	2005-03-09 19:43:47.139924394 +0100
@@ -24,6 +24,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
+#include <sys/un.h>
 #include <unistd.h>
 
 char *temp_filename;
@@ -463,11 +465,22 @@ do_test (void)
   if (fgets (buf, sizeof (buf), stdin) != buf || memcmp (buf, "ABCDEFGHI", 10))
     FAIL ();
 
+  rewind (stdin);
+
+  if (fgets (buf, l0 + sizeof (buf), stdin) != buf
+      || memcmp (buf, "abcdefgh\n", 10))
+    FAIL ();
+
 #if __USE_FORTIFY_LEVEL >= 1
   CHK_FAIL_START
   if (fgets (buf, sizeof (buf) + 1, stdin) != buf)
     FAIL ();
   CHK_FAIL_END
+
+  CHK_FAIL_START
+  if (fgets (buf, l0 + sizeof (buf) + 1, stdin) != buf)
+    FAIL ();
+  CHK_FAIL_END
 #endif
 
   rewind (stdin);
@@ -479,11 +492,22 @@ do_test (void)
       || memcmp (buf, "ABCDEFGHI", 10))
     FAIL ();
 
+  rewind (stdin);
+
+  if (fgets_unlocked (buf, l0 + sizeof (buf), stdin) != buf
+      || memcmp (buf, "abcdefgh\n", 10))
+    FAIL ();
+
 #if __USE_FORTIFY_LEVEL >= 1
   CHK_FAIL_START
   if (fgets_unlocked (buf, sizeof (buf) + 1, stdin) != buf)
     FAIL ();
   CHK_FAIL_END
+
+  CHK_FAIL_START
+  if (fgets_unlocked (buf, l0 + sizeof (buf) + 1, stdin) != buf)
+    FAIL ();
+  CHK_FAIL_END
 #endif
 
   lseek (fileno (stdin), 0, SEEK_SET);
@@ -495,6 +519,12 @@ do_test (void)
       || memcmp (buf, "ABCDEFGHI", 9))
     FAIL ();
 
+  lseek (fileno (stdin), 0, SEEK_SET);
+
+  if (read (fileno (stdin), buf, l0 + sizeof (buf) - 1) != sizeof (buf) - 1
+      || memcmp (buf, "abcdefgh\n", 9))
+    FAIL ();
+
 #if __USE_FORTIFY_LEVEL >= 1
   CHK_FAIL_START
   if (read (fileno (stdin), buf, sizeof (buf) + 1) != sizeof (buf) + 1)
@@ -502,12 +532,16 @@ do_test (void)
   CHK_FAIL_END
 #endif
 
+  if (pread (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 2)
+      != sizeof (buf) - 1
+      || memcmp (buf, "\nABCDEFGH", 9))
+    FAIL ();
   if (pread (fileno (stdin), buf, sizeof (buf) - 1, 0) != sizeof (buf) - 1
       || memcmp (buf, "abcdefgh\n", 9))
     FAIL ();
-  if (pread (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 1)
+  if (pread (fileno (stdin), buf, l0 + sizeof (buf) - 1, sizeof (buf) - 3)
       != sizeof (buf) - 1
-      || memcmp (buf, "ABCDEFGHI", 9))
+      || memcmp (buf, "h\nABCDEFG", 9))
     FAIL ();
 
 #if __USE_FORTIFY_LEVEL >= 1
@@ -518,17 +552,21 @@ do_test (void)
   CHK_FAIL_END
 #endif
 
+  if (pread64 (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 2)
+      != sizeof (buf) - 1
+      || memcmp (buf, "\nABCDEFGH", 9))
+    FAIL ();
   if (pread64 (fileno (stdin), buf, sizeof (buf) - 1, 0) != sizeof (buf) - 1
       || memcmp (buf, "abcdefgh\n", 9))
     FAIL ();
-  if (pread64 (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 1)
+  if (pread64 (fileno (stdin), buf, l0 + sizeof (buf) - 1, sizeof (buf) - 3)
       != sizeof (buf) - 1
-      || memcmp (buf, "ABCDEFGHI", 9))
+      || memcmp (buf, "h\nABCDEFG", 9))
     FAIL ();
 
 #if __USE_FORTIFY_LEVEL >= 1
   CHK_FAIL_START
-  if (pread64 (fileno (stdin), buf, sizeof (buf) + 1, 2 * (sizeof (buf) - 1))
+  if (pread64 (fileno (stdin), buf, sizeof (buf) + 1, 2 * sizeof (buf))
       != sizeof (buf) + 1)
     FAIL ();
   CHK_FAIL_END
@@ -570,5 +608,188 @@ do_test (void)
   snprintf (buf, sizeof (buf), "%3$d\n", 1, 2, 3, 4);
   CHK_FAIL2_END
 
+  int sp[2];
+  if (socketpair (PF_UNIX, SOCK_STREAM, 0, sp))
+    FAIL ();
+  else
+    {
+      const char *sendstr = "abcdefgh\nABCDEFGH\n0123456789\n";
+      if (send (sp[0], sendstr, strlen (sendstr), 0) != strlen (sendstr))
+	FAIL ();
+
+      char recvbuf[12];
+      if (recv (sp[1], recvbuf, sizeof recvbuf, MSG_PEEK)
+	  != sizeof recvbuf
+	  || memcmp (recvbuf, sendstr, sizeof recvbuf) != 0)
+	FAIL ();
+
+      if (recv (sp[1], recvbuf + 6, l0 + sizeof recvbuf - 7, MSG_PEEK)
+	  != sizeof recvbuf - 7
+	  || memcmp (recvbuf + 6, sendstr, sizeof recvbuf - 7) != 0)
+	FAIL ();
+
+#if __USE_FORTIFY_LEVEL >= 1
+      CHK_FAIL_START
+      if (recv (sp[1], recvbuf + 1, sizeof recvbuf, MSG_PEEK)
+	  != sizeof recvbuf)
+	FAIL ();
+      CHK_FAIL_END
+
+      CHK_FAIL_START
+      if (recv (sp[1], recvbuf + 4, l0 + sizeof recvbuf - 3, MSG_PEEK)
+	  != sizeof recvbuf - 3)
+	FAIL ();
+      CHK_FAIL_END
+#endif
+
+      socklen_t sl;
+      struct sockaddr_un sa_un;
+
+      sl = sizeof (sa_un);
+      if (recvfrom (sp[1], recvbuf, sizeof recvbuf, MSG_PEEK, &sa_un, &sl)
+	  != sizeof recvbuf
+	  || memcmp (recvbuf, sendstr, sizeof recvbuf) != 0)
+	FAIL ();
+
+      sl = sizeof (sa_un);
+      if (recvfrom (sp[1], recvbuf + 6, l0 + sizeof recvbuf - 7, MSG_PEEK,
+	  &sa_un, &sl) != sizeof recvbuf - 7
+	  || memcmp (recvbuf + 6, sendstr, sizeof recvbuf - 7) != 0)
+	FAIL ();
+
+#if __USE_FORTIFY_LEVEL >= 1
+      CHK_FAIL_START
+      sl = sizeof (sa_un);
+      if (recvfrom (sp[1], recvbuf + 1, sizeof recvbuf, MSG_PEEK, &sa_un, &sl)
+	  != sizeof recvbuf)
+	FAIL ();
+      CHK_FAIL_END
+
+      CHK_FAIL_START
+      sl = sizeof (sa_un);
+      if (recvfrom (sp[1], recvbuf + 4, l0 + sizeof recvbuf - 3, MSG_PEEK,
+	  &sa_un, &sl) != sizeof recvbuf - 3)
+	FAIL ();
+      CHK_FAIL_END
+#endif
+
+      close (sp[0]);
+      close (sp[1]);
+    }
+
+  char fname[] = "/tmp/tst-chk1-dir-XXXXXX\0foo";
+  char *enddir = strchr (fname, '\0');
+  if (mkdtemp (fname) == NULL)
+    {
+      printf ("mkdtemp failed: %m\n");
+      return 1;
+    }
+  *enddir = '/';
+  if (symlink ("bar", fname) != 0)
+    FAIL ();
+
+  char readlinkbuf[4];
+  if (readlink (fname, readlinkbuf, 4) != 3
+      || memcmp (readlinkbuf, "bar", 3) != 0)
+    FAIL ();
+  if (readlink (fname, readlinkbuf + 1, l0 + 3) != 3
+      || memcmp (readlinkbuf, "bbar", 4) != 0)
+    FAIL ();
+
+#if __USE_FORTIFY_LEVEL >= 1
+  CHK_FAIL_START
+  if (readlink (fname, readlinkbuf + 2, l0 + 3) != 3)
+    FAIL ();
+  CHK_FAIL_END
+
+  CHK_FAIL_START
+  if (readlink (fname, readlinkbuf + 3, 4) != 3)
+    FAIL ();
+  CHK_FAIL_END
+#endif
+
+  char *cwd1 = getcwd (NULL, 0);
+  if (cwd1 == NULL)
+    FAIL ();
+
+  char *cwd2 = getcwd (NULL, 250);
+  if (cwd2 == NULL)
+    FAIL ();
+
+  if (cwd1 && cwd2)
+    {
+      if (strcmp (cwd1, cwd2) != 0)
+	FAIL ();
+
+      *enddir = '\0';
+      if (chdir (fname))
+	FAIL ();
+
+      char *cwd3 = getcwd (NULL, 0);
+      if (cwd3 == NULL)
+	FAIL ();
+      if (strcmp (fname, cwd3) != 0)
+	printf ("getcwd after chdir is '%s' != '%s',"
+		"get{c,}wd tests skipped\n", cwd3, fname);
+      else
+	{
+	  char getcwdbuf[sizeof fname - 3];
+
+	  char *cwd4 = getcwd (getcwdbuf, sizeof getcwdbuf);
+	  if (cwd4 != getcwdbuf
+	      || strcmp (getcwdbuf, fname) != 0)
+	    FAIL ();
+
+	  cwd4 = getcwd (getcwdbuf + 1, l0 + sizeof getcwdbuf - 1);
+	  if (cwd4 != getcwdbuf + 1
+	      || getcwdbuf[0] != fname[0]
+	      || strcmp (getcwdbuf + 1, fname) != 0)
+	    FAIL ();
+
+#if __USE_FORTIFY_LEVEL >= 1
+	  CHK_FAIL_START
+	  if (getcwd (getcwdbuf + 2, l0 + sizeof getcwdbuf)
+	      != getcwdbuf + 2)
+	    FAIL ();
+	  CHK_FAIL_END
+
+	  CHK_FAIL_START
+	  if (getcwd (getcwdbuf + 2, sizeof getcwdbuf)
+	      != getcwdbuf + 2)
+	    FAIL ();
+	  CHK_FAIL_END
+#endif
+
+	  if (getwd (getcwdbuf) != getcwdbuf
+	      || strcmp (getcwdbuf, fname) != 0)
+	    FAIL ();
+
+	  if (getwd (getcwdbuf + 1) != getcwdbuf + 1
+	      || strcmp (getcwdbuf + 1, fname) != 0)
+	    FAIL ();
+
+#if __USE_FORTIFY_LEVEL >= 1
+	  CHK_FAIL_START
+	  if (getwd (getcwdbuf + 2) != getcwdbuf + 2)
+	    FAIL ();
+	  CHK_FAIL_END
+#endif
+	}
+
+      if (chdir (cwd1) != 0)
+	FAIL ();
+      free (cwd3);
+    }
+
+  free (cwd1);
+  free (cwd2);
+  *enddir = '/';
+  if (unlink (fname) != 0)
+    FAIL ();
+
+  *enddir = '\0';
+  if (rmdir (fname) != 0)
+    FAIL ();
+
   return ret;
 }
--- libc/debug/pread64_chk.c.jj	2005-03-01 10:34:26.000000000 +0100
+++ libc/debug/pread64_chk.c	2005-03-09 17:12:30.524596022 +0100
@@ -26,5 +26,5 @@ __pread64_chk (int fd, void *buf, size_t
   if (nbytes > buflen)
     __chk_fail ();
 
-  return __pread64 (fd, buf, offset, nbytes);
+  return __pread64 (fd, buf, nbytes, offset);
 }
--- libc/libio/bits/stdio2.h.jj	2005-02-22 10:02:16.000000000 +0100
+++ libc/libio/bits/stdio2.h	2005-03-09 18:13:38.338616626 +0100
@@ -72,18 +72,42 @@ extern int __vprintf_chk (int __flag, __
 
 #endif
 
-extern char *__gets_chk (char *__str, size_t);
-#define gets(__str) \
-  ((__bos (__str) == (size_t) -1)					      \
-   ? gets (__str) : __gets_chk (__str, __bos (__str)))
+extern char *__gets_chk (char *__str, size_t) __wur;
+extern char *__REDIRECT (__gets_alias, (char *__str), gets) __wur;
+extern __inline __wur char *
+gets (char *__str)
+{
+  if (__bos (__str) != (size_t) -1)
+    return __gets_chk (__str, __bos (__str));
+  return __gets_alias (__str);
+}
 
-extern char *__fgets_chk (char *s, size_t size, int n, FILE *stream);
-#define fgets(__str, __n, __fp) \
-  ((__bos (__str) == (size_t) -1)					      \
-   ? fgets (__str, __n, __fp) : __fgets_chk (__str, __bos (__str), __n, __fp))
+extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n,
+			  FILE *__restrict __stream) __wur;
+extern char *__REDIRECT (__fgets_alias,
+			 (char *__restrict __s, int __n,
+			  FILE *__restrict __stream), fgets) __wur;
+extern __inline __wur char *
+fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
+{
+  if (__bos (__s) != (size_t) -1
+      && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s)))
+    return __fgets_chk (__s, __bos (__s), __n, __stream);
+  return __fgets_alias (__s, __n, __stream);
+}
 
-extern char *__fgets_unlocked_chk (char *s, size_t size, int n, FILE *stream);
-#define fgets_unlocked(__str, __n, __fp) \
-  ((__bos (__str) == (size_t) -1)					      \
-   ? fgets_unlocked (__str, __n, __fp)					      \
-   : __fgets_unlocked_chk (__str, __bos (__str), __n, __fp))
+#ifdef __USE_GNU
+extern char *__fgets_unlocked_chk (char *__restrict __s, size_t __size,
+				   int __n, FILE *__restrict __stream) __wur;
+extern char *__REDIRECT (__fgets_unlocked_alias,
+			 (char *__restrict __s, int __n,
+			  FILE *__restrict __stream), fgets_unlocked) __wur;
+extern __inline __wur char *
+fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream)
+{
+  if (__bos (__s) != (size_t) -1
+      && (!__builtin_constant_p (__n) || (size_t) __n > __bos (__s)))
+    return __fgets_unlocked_chk (__s, __bos (__s), __n, __stream);
+  return __fgets_unlocked_alias (__s, __n, __stream);
+}
+#endif

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]