]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
Check if realpath works on nonexistent files.
authorDarren Tucker <dtucker@zip.com.au>
Fri, 17 Jul 2015 02:52:34 +0000 (12:52 +1000)
committerDarren Tucker <dtucker@zip.com.au>
Fri, 17 Jul 2015 02:58:02 +0000 (12:58 +1000)
On some platforms the native realpath doesn't work with non-existent
files (this is actually specified in some versions of POSIX), however
the sftp spec says its realpath with "canonicalize any given path name".
On those platforms, use realpath from the compat library.

In addition, when compiling with -DFORTIFY_SOURCE, glibc redefines
the realpath symbol to the checked version, so redefine ours to
something else so we pick up the compat version we want.

bz#2428, ok djm@

configure.ac
openbsd-compat/openbsd-compat.h

index 2240c725c46dc51eee4fdc0ff98f372ab3fe7bec..9b05c30f897af1384bdcb0488f5d74870253985c 100644 (file)
@@ -1674,7 +1674,6 @@ AC_CHECK_FUNCS([ \
        pstat \
        readpassphrase \
        reallocarray \
-       realpath \
        recvmsg \
        rresvport_af \
        sendmsg \
@@ -1891,6 +1890,32 @@ AC_CHECK_FUNCS([setresgid], [
        )
 ])
 
+AC_CHECK_FUNCS([realpath], [
+       dnl the sftp v3 spec says SSH_FXP_REALPATH will "canonicalize any given
+       dnl path name", however some implementations of realpath (and some
+       dnl versions of the POSIX spec) do not work on non-existent files,
+       dnl so we use the OpenBSD implementation on those platforms.
+       AC_MSG_CHECKING([if realpath works with non-existent files])
+       AC_RUN_IFELSE(
+               [AC_LANG_PROGRAM([[
+#include <limits.h>
+#include <stdlib.h>
+#include <errno.h>
+               ]], [[
+               char buf[PATH_MAX];
+               if (realpath("/opensshnonexistentfilename1234", buf) == NULL)
+                       if (errno == ENOENT)
+                               exit(1);
+               exit(0);
+               ]])],
+               [AC_MSG_RESULT([yes])],
+               [AC_DEFINE([BROKEN_REALPATH], [1],
+                       [realpath does not work with nonexistent files])
+                AC_MSG_RESULT([no])],
+               [AC_MSG_WARN([cross compiling: assuming working])]
+       )
+])
+
 dnl    Checks for time functions
 AC_CHECK_FUNCS([gettimeofday time])
 dnl    Checks for utmp functions
index cb59ccd5783499e39460bf1bb7b2c8106a9f22be..1ff7114ef3daedeb000ce40ae8e001355bd12850 100644 (file)
@@ -70,8 +70,16 @@ void *reallocarray(void *, size_t, size_t);
 #endif
 
 #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH)
+/*
+ * glibc's FORTIFY_SOURCE can redefine this and prevent us picking up the
+ * compat version.
+ */
+# ifdef BROKEN_REALPATH
+#  define realpath(x, y) _ssh_compat_realpath(x, y)
+# endif
+
 char *realpath(const char *path, char *resolved);
-#endif 
+#endif
 
 #ifndef HAVE_RRESVPORT_AF
 int rresvport_af(int *alport, sa_family_t af);