Change stat order for better ELOOP determination.
authorWayne Davison <wayned@samba.org>
Tue, 20 Sep 2011 20:02:12 +0000 (13:02 -0700)
committerWayne Davison <wayned@samba.org>
Tue, 20 Sep 2011 20:02:12 +0000 (13:02 -0700)
syscall.c

index e2b1394a911200a063c8cda16db86c4a25b4e2f3..5a7c8e82652b27df7a66712592d2d4b5d26d454d 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -464,9 +464,14 @@ int do_open_nofollow(const char *pathname, int flags)
 #ifdef O_NOFOLLOW
        fd = open(pathname, flags|O_NOFOLLOW);
 #else
+       if (do_lstat(pathname, &l_st) < 0)
+               return -1;
+       if (S_ISLNK(l_st.st_mode)) {
+               errno = ELOOP;
+               return -1;
+       }
        if ((fd = open(pathname, flags)) < 0)
                return fd;
-
        if (do_fstat(fd, &f_st) < 0) {
          close_and_return_error:
                {
@@ -476,12 +481,6 @@ int do_open_nofollow(const char *pathname, int flags)
                }
                return -1;
        }
-       if (do_lstat(pathname, &l_st) < 0)
-               goto close_and_return_error;
-       if (S_ISLNK(l_st.st_mode)) {
-               errno = ELOOP;
-               goto close_and_return_error;
-       }
        if (l_st.st_dev != f_st.st_dev || l_st.st_ino != f_st.st_ino) {
                errno = EINVAL;
                goto close_and_return_error;