]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nis/nis_lookup.c
Fix unbound stack use in NIS NSS module
[thirdparty/glibc.git] / nis / nis_lookup.c
index 839ee4ee42e976a269ad9526558534de02c879af..b9096c9ea4fd1836f75a9408d01a1d198fd1e469 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997-1999, 2004, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2014 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1997.
 
@@ -13,9 +13,8 @@
    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.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <string.h>
 #include <rpcsvc/nis.h>
@@ -64,7 +63,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
       req.ns_object.ns_object_val = NULL;
 
       status = __prepare_niscall (req.ns_name, &dir, &bptr, flags);
-      if (__builtin_expect (status != NIS_SUCCESS, 0))
+      if (__glibc_unlikely (status != NIS_SUCCESS))
        {
          NIS_RES_STATUS (res) = status;
          goto out;
@@ -74,7 +73,6 @@ nis_lookup (const_nis_name name, const unsigned int flags)
        {
          static const struct timeval RPCTIMEOUT = {10, 0};
          enum clnt_stat result;
-         char ndomain[strlen (req.ns_name) + 1];
 
        again:
          result = clnt_call (bptr.clnt, NIS_LOOKUP,
@@ -127,27 +125,18 @@ nis_lookup (const_nis_name name, const unsigned int flags)
                        /* Otherwise __nisfind_server will not do anything.  */
                        dir = NULL;
 
-                       if (__nisfind_server (req.ns_name, 1, &dir)
+                       if (__nisfind_server (req.ns_name, 1, &dir, &bptr,
+                                             flags & ~MASTER_ONLY)
                            != NIS_SUCCESS)
                          goto out;
-
-                       if (__nisbind_create (&bptr,
-                                             dir->do_servers.do_servers_val,
-                                             dir->do_servers.do_servers_len,
-                                             flags) != NIS_SUCCESS)
-                         {
-                           nis_free_directory (dir);
-                           goto out;
-                         }
                      }
                    else
                      if (__nisbind_next (&bptr) != NIS_SUCCESS)
                        {
                          /* No more servers to search.  Try parent.  */
-                         nis_domain_of_r (req.ns_name, ndomain,
-                                          sizeof (ndomain));
+                         const char *ndomain = __nis_domain_of (req.ns_name);
                          req.ns_name = strdupa (ndomain);
-                         if (strcmp (ndomain, ".") == 0)
+                         if (strcmp (req.ns_name, ".") == 0)
                            {
                              NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
                              goto out;
@@ -158,7 +147,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
                          dir = NULL;
                          status = __prepare_niscall (req.ns_name, &dir,
                                                      &bptr, flags);
-                         if (__builtin_expect (status != NIS_SUCCESS, 0))
+                         if (__glibc_unlikely (status != NIS_SUCCESS))
                            {
                              NIS_RES_STATUS (res) = status;
                              goto out;