Advertisement
Guest User

cve-2015-0235-lenny.diff

a guest
Jan 28th, 2015
1,699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.34 KB | None | 0 0
  1. diff --git a/nss/Makefile b/nss/Makefile
  2. index 449a258..553eafa 100644
  3. --- a/nss/Makefile
  4. +++ b/nss/Makefile
  5. @@ -37,7 +37,7 @@ install-bin             := getent makedb
  6.  makedb-modules = xmalloc hash-string
  7.  extra-objs             += $(makedb-modules:=.o)
  8.  
  9. -tests                  = test-netdb
  10. +tests                  = test-netdb test-digits-dots
  11.  xtests                 = bug-erange
  12.  
  13.  include ../Makeconfig
  14. diff --git a/nss/digits_dots.c b/nss/digits_dots.c
  15. index 2b86295..e007ef4 100644
  16. --- a/nss/digits_dots.c
  17. +++ b/nss/digits_dots.c
  18. @@ -46,7 +46,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
  19.      {
  20.        if (h_errnop)
  21.         *h_errnop = NETDB_INTERNAL;
  22. -      *result = NULL;
  23. +      if (buffer_size == NULL)
  24. +       *status = NSS_STATUS_TRYAGAIN;
  25. +      else
  26. +       *result = NULL;
  27.        return -1;
  28.      }
  29.  
  30. @@ -83,14 +86,16 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
  31.         }
  32.  
  33.        size_needed = (sizeof (*host_addr)
  34. -                    + sizeof (*h_addr_ptrs) + strlen (name) + 1);
  35. +                    + sizeof (*h_addr_ptrs)
  36. +                    + sizeof (*h_alias_ptr) + strlen (name) + 1);
  37.  
  38.        if (buffer_size == NULL)
  39.          {
  40.           if (buflen < size_needed)
  41.             {
  42. +             *status = NSS_STATUS_TRYAGAIN;
  43.               if (h_errnop != NULL)
  44. -               *h_errnop = TRY_AGAIN;
  45. +               *h_errnop = NETDB_INTERNAL;
  46.               __set_errno (ERANGE);
  47.               goto done;
  48.             }
  49. @@ -109,7 +114,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
  50.               *buffer_size = 0;
  51.               __set_errno (save);
  52.               if (h_errnop != NULL)
  53. -               *h_errnop = TRY_AGAIN;
  54. +               *h_errnop = NETDB_INTERNAL;
  55.               *result = NULL;
  56.               goto done;
  57.             }
  58. @@ -149,7 +154,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
  59.                   if (! ok)
  60.                     {
  61.                       *h_errnop = HOST_NOT_FOUND;
  62. -                     if (buffer_size)
  63. +                     if (buffer_size == NULL)
  64. +                       *status = NSS_STATUS_NOTFOUND;
  65. +                     else
  66.                         *result = NULL;
  67.                       goto done;
  68.                     }
  69. @@ -190,7 +197,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
  70.                   if (buffer_size == NULL)
  71.                     *status = NSS_STATUS_SUCCESS;
  72.                   else
  73. -                  *result = resbuf;
  74. +                   *result = resbuf;
  75.                   goto done;
  76.                 }
  77.  
  78. @@ -201,15 +208,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
  79.  
  80.        if ((isxdigit (name[0]) && strchr (name, ':') != NULL) || name[0] == ':')
  81.         {
  82. -         const char *cp;
  83. -         char *hostname;
  84. -         typedef unsigned char host_addr_t[16];
  85. -         host_addr_t *host_addr;
  86. -         typedef char *host_addr_list_t[2];
  87. -         host_addr_list_t *h_addr_ptrs;
  88. -         size_t size_needed;
  89. -         int addr_size;
  90. -
  91.           switch (af)
  92.             {
  93.             default:
  94. @@ -225,7 +223,10 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
  95.               /* This is not possible.  We cannot represent an IPv6 address
  96.                  in an `struct in_addr' variable.  */
  97.               *h_errnop = HOST_NOT_FOUND;
  98. -             *result = NULL;
  99. +             if (buffer_size == NULL)
  100. +               *status = NSS_STATUS_NOTFOUND;
  101. +             else
  102. +               *result = NULL;
  103.               goto done;
  104.  
  105.             case AF_INET6:
  106. @@ -233,42 +234,6 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
  107.               break;
  108.             }
  109.  
  110. -         size_needed = (sizeof (*host_addr)
  111. -                        + sizeof (*h_addr_ptrs) + strlen (name) + 1);
  112. -
  113. -         if (buffer_size == NULL && buflen < size_needed)
  114. -           {
  115. -             if (h_errnop != NULL)
  116. -               *h_errnop = TRY_AGAIN;
  117. -             __set_errno (ERANGE);
  118. -             goto done;
  119. -           }
  120. -         else if (buffer_size != NULL && *buffer_size < size_needed)
  121. -           {
  122. -             char *new_buf;
  123. -             *buffer_size = size_needed;
  124. -             new_buf = realloc (*buffer, *buffer_size);
  125. -
  126. -             if (new_buf == NULL)
  127. -               {
  128. -                 save = errno;
  129. -                 free (*buffer);
  130. -                 __set_errno (save);
  131. -                 *buffer = NULL;
  132. -                 *buffer_size = 0;
  133. -                 *result = NULL;
  134. -                 goto done;
  135. -               }
  136. -             *buffer = new_buf;
  137. -           }
  138. -
  139. -         memset (*buffer, '\0', size_needed);
  140. -
  141. -         host_addr = (host_addr_t *) *buffer;
  142. -         h_addr_ptrs = (host_addr_list_t *)
  143. -           ((char *) host_addr + sizeof (*host_addr));
  144. -         hostname = (char *) h_addr_ptrs + sizeof (*h_addr_ptrs);
  145. -
  146.           for (cp = name;; ++cp)
  147.             {
  148.               if (!*cp)
  149. @@ -281,7 +246,9 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
  150.                   if (inet_pton (AF_INET6, name, host_addr) <= 0)
  151.                     {
  152.                       *h_errnop = HOST_NOT_FOUND;
  153. -                     if (buffer_size)
  154. +                     if (buffer_size == NULL)
  155. +                       *status = NSS_STATUS_NOTFOUND;
  156. +                     else
  157.                         *result = NULL;
  158.                       goto done;
  159.                     }
  160. diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
  161. index 1067744..44d00f4 100644
  162. --- a/nss/getXXbyYY_r.c
  163. +++ b/nss/getXXbyYY_r.c
  164. @@ -179,6 +179,9 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
  165.      case -1:
  166.        return errno;
  167.      case 1:
  168. +#ifdef NEED_H_ERRNO
  169. +      any_service = true;
  170. +#endif
  171.        goto done;
  172.      }
  173.  #endif
  174. diff --git a/nss/test-digits-dots.c b/nss/test-digits-dots.c
  175. new file mode 100644
  176. index 0000000..1efa344
  177. --- /dev/null
  178. +++ b/nss/test-digits-dots.c
  179. @@ -0,0 +1,38 @@
  180. +/* Copyright (C) 2013 Free Software Foundation, Inc.
  181. +   This file is part of the GNU C Library.
  182. +
  183. +   The GNU C Library is free software; you can redistribute it and/or
  184. +   modify it under the terms of the GNU Lesser General Public
  185. +   License as published by the Free Software Foundation; either
  186. +   version 2.1 of the License, or (at your option) any later version.
  187. +
  188. +   The GNU C Library is distributed in the hope that it will be useful,
  189. +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  190. +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  191. +   Lesser General Public License for more details.
  192. +
  193. +   You should have received a copy of the GNU Lesser General Public
  194. +   License along with the GNU C Library; if not, see
  195. +   <http://www.gnu.org/licenses/>.  */
  196. +
  197. +/* Testcase for BZ #15014 */
  198. +
  199. +#include <stdlib.h>
  200. +#include <netdb.h>
  201. +#include <errno.h>
  202. +
  203. +static int
  204. +do_test (void)
  205. +{
  206. +  char buf[32];
  207. +  struct hostent *result = NULL;
  208. +  struct hostent ret;
  209. +  int h_err = 0;
  210. +  int err;
  211. +
  212. +  err = gethostbyname_r ("1.2.3.4", &ret, buf, sizeof (buf), &result, &h_err);
  213. +  return err == ERANGE && h_err == NETDB_INTERNAL ? EXIT_SUCCESS : EXIT_FAILURE;
  214. +}
  215. +
  216. +#define TEST_FUNCTION do_test ()
  217. +#include "../test-skeleton.c"
  218. --
  219. 1.7.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement