bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] fdopendir: work around FreeBSD bug


From: Eric Blake
Subject: [PATCH] fdopendir: work around FreeBSD bug
Date: Mon, 29 Mar 2010 15:22:20 -0600

Without a declaration, at least tar would core dump on 64-bit
FreeBSD because gcc only used 32 bits of the resulting pointer.

* m4/dirent_h.m4 (gl_DIRENT_H_DEFAULTS): New witness.
* m4/fdopendir.m4 (gl_FUNC_FDOPENDIR): Set it.
* modules/dirent (Makefile.am): Substitute it.
* lib/dirent.in.h (fdopendir): Supply missing FreeBSD
declaration.
* doc/posix-functions/fdopendir.texi (fdopendir): Document the
fix.
Reported by Christian Weisgerber <address@hidden>.

Signed-off-by: Eric Blake <address@hidden>
---

I'm still trying to get access to a FreeBSD 7 box to test this out
myself (my current FreeBSD access is running 8.0, but that does not
have the bug).  I'll probably push this tomorrow, hoping either for
some positive feedback or for a successful reproduction of the problem
myself in the meantime.

 ChangeLog                          |   12 ++++++++++++
 doc/posix-functions/fdopendir.texi |    3 +++
 lib/dirent.in.h                    |    2 +-
 m4/dirent_h.m4                     |    3 ++-
 m4/fdopendir.m4                    |    7 ++++++-
 modules/dirent                     |    1 +
 6 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b6f1dc1..1367dd0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-03-29  Eric Blake  <address@hidden>
+
+       fdopendir: work around FreeBSD bug
+       * m4/dirent_h.m4 (gl_DIRENT_H_DEFAULTS): New witness.
+       * m4/fdopendir.m4 (gl_FUNC_FDOPENDIR): Set it.
+       * modules/dirent (Makefile.am): Substitute it.
+       * lib/dirent.in.h (fdopendir): Supply missing FreeBSD
+       declaration.
+       * doc/posix-functions/fdopendir.texi (fdopendir): Document the
+       fix.
+       Reported by Christian Weisgerber <address@hidden>.
+
 2010-03-28  James Youngman  <address@hidden>

        save-cwd: don't leak a file descriptor when the caller execs.
diff --git a/doc/posix-functions/fdopendir.texi 
b/doc/posix-functions/fdopendir.texi
index fae7bb7..89b1a6a 100644
--- a/doc/posix-functions/fdopendir.texi
+++ b/doc/posix-functions/fdopendir.texi
@@ -17,6 +17,9 @@ fdopendir
 that @samp{dirfd(fdopendir(n))==n} (dirfd might fail, or return a
 different file descriptor than n).
 @item
+This function exists but is not declared on some platforms:
+FreeBSD 7.3.
address@hidden
 This function does not reject non-directory file descriptors on some
 platforms:
 GNU/Hurd.
diff --git a/lib/dirent.in.h b/lib/dirent.in.h
index 15d488b..a7dd6d3 100644
--- a/lib/dirent.in.h
+++ b/lib/dirent.in.h
@@ -77,7 +77,7 @@ _GL_WARN_ON_USE (dirfd, "dirfd is unportable - "
 _GL_FUNCDECL_RPL (fdopendir, DIR *, (int fd));
 _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
 # else
-#  if address@hidden@
+#  if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (fdopendir, DIR *, (int fd));
 #  endif
 _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
diff --git a/m4/dirent_h.m4 b/m4/dirent_h.m4
index 5f88a27..361296a 100644
--- a/m4/dirent_h.m4
+++ b/m4/dirent_h.m4
@@ -1,4 +1,4 @@
-# dirent_h.m4 serial 11
+# dirent_h.m4 serial 12
 dnl Copyright (C) 2008-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -46,6 +46,7 @@ AC_DEFUN([gl_DIRENT_H_DEFAULTS],
   GNULIB_ALPHASORT=0;   AC_SUBST([GNULIB_ALPHASORT])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DECL_DIRFD=1;    AC_SUBST([HAVE_DECL_DIRFD])
+  HAVE_DECL_FDOPENDIR=1;AC_SUBST([HAVE_DECL_FDOPENDIR])
   HAVE_FDOPENDIR=1;     AC_SUBST([HAVE_FDOPENDIR])
   HAVE_SCANDIR=1;       AC_SUBST([HAVE_SCANDIR])
   HAVE_ALPHASORT=1;     AC_SUBST([HAVE_ALPHASORT])
diff --git a/m4/fdopendir.m4 b/m4/fdopendir.m4
index 7282d4b..1207917 100644
--- a/m4/fdopendir.m4
+++ b/m4/fdopendir.m4
@@ -1,4 +1,4 @@
-# serial 3
+# serial 4
 # See if we need to provide fdopendir.

 dnl Copyright (C) 2009-2010 Free Software Foundation, Inc.
@@ -35,4 +35,9 @@ AC_DEFUN([gl_FUNC_FDOPENDIR],
       AC_LIBOBJ([fdopendir])
     fi
   fi
+  dnl FreeBSD 7.3 has the function, but failed to declare it.
+  AC_CHECK_DECLS([fdopendir], [], [HAVE_DECL_FDOPENDIR=0], [[
+#include <dirent.h>
+#include <fcntl.h>
+    ]])
 ])
diff --git a/modules/dirent b/modules/dirent
index 9b99dbc..8783d83 100644
--- a/modules/dirent
+++ b/modules/dirent
@@ -31,6 +31,7 @@ dirent.h: dirent.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''GNULIB_SCANDIR''@|$(GNULIB_SCANDIR)|g' \
              -e 's|@''GNULIB_ALPHASORT''@|$(GNULIB_ALPHASORT)|g' \
              -e 's|@''HAVE_DECL_DIRFD''@|$(HAVE_DECL_DIRFD)|g' \
+             -e 's|@''HAVE_DECL_FDOPENDIR''@|$(HAVE_DECL_FDOPENDIR)|g' \
              -e 's|@''HAVE_FDOPENDIR''@|$(HAVE_FDOPENDIR)|g' \
              -e 's|@''HAVE_SCANDIR''@|$(HAVE_SCANDIR)|g' \
              -e 's|@''HAVE_ALPHASORT''@|$(HAVE_ALPHASORT)|g' \
-- 
1.6.6.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]