Print this page
1926 libresolv evades compiler warnings

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libresolv/res_gethost.c
          +++ new/usr/src/lib/libresolv/res_gethost.c
   1    1  /*
        2 + * Copyright 2015 Gary Mills
   2    3   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
   3    4   * Use is subject to license terms.
   4    5   */
   5    6  
   6    7  /*
   7    8   * Copyright (c) 1985, 1988 Regents of the University of California.
   8    9   * All rights reserved.
   9   10   *
  10   11   * Redistribution and use in source and binary forms are permitted
  11   12   * provided that this notice is preserved and that due credit is given
↓ open down ↓ 4 lines elided ↑ open up ↑
  16   17   *
  17   18   */
  18   19  
  19   20  #include <sys/param.h>
  20   21  #include <sys/socket.h>
  21   22  #include <netinet/in.h>
  22   23  #include <ctype.h>
  23   24  #include <netdb.h>
  24   25  #include <stdio.h>
  25   26  #include <errno.h>
       27 +#include <string.h>
  26   28  #include <arpa/inet.h>
  27   29  #include <arpa/nameser.h>
  28   30  #include <resolv.h>
  29   31  #include <syslog.h>
       32 +#include "crossl.h"
  30   33  
  31   34  /*
  32   35   * When the name service switch calls libresolv, it doesn't want fallback
  33   36   * to /etc/hosts, so we provide a method to turn it off.
  34   37   */
  35   38  static int      no_hosts_fallback = 0;
  36   39  
  37   40  void
  38   41  __res_set_no_hosts_fallback(void) {
  39   42          no_hosts_fallback = 1;
↓ open down ↓ 56 lines elided ↑ open up ↑
  96   99           * find first satisfactory answer
  97  100           */
  98  101          hp = &answer->hdr;
  99  102          ancount = ntohs(hp->ancount);
 100  103          qdcount = ntohs(hp->qdcount);
 101  104          bp = hostbuf;
 102  105          buflen = sizeof (hostbuf);
 103  106          cp = answer->buf + sizeof (HEADER);
 104  107          if (qdcount) {
 105  108                  if (iquery) {
 106      -                        if ((n = dn_expand((char *)answer->buf, eom,
 107      -                                                cp, bp, buflen)) < 0) {
      109 +                        if ((n = dn_expand(answer->buf, eom,
      110 +                            cp, (u_char *)bp, buflen)) < 0) {
 108  111                                  h_errno = NO_RECOVERY;
 109  112                                  return ((struct hostent *) NULL);
 110  113                          }
 111  114                          cp += n + QFIXEDSZ;
 112  115                          host.h_name = bp;
 113  116                          n = strlen(bp) + 1;
 114  117                          bp += n;
 115  118                          buflen -= n;
 116  119                  } else
 117  120                          cp += dn_skipname(cp, eom) + QFIXEDSZ;
↓ open down ↓ 7 lines elided ↑ open up ↑
 125  128                  return ((struct hostent *) NULL);
 126  129          }
 127  130          ap = host_aliases;
 128  131          host.h_aliases = host_aliases;
 129  132          hap = h_addr_ptrs;
 130  133  #if BSD >= 43 || defined(h_addr)        /* new-style hostent structure */
 131  134          host.h_addr_list = h_addr_ptrs;
 132  135  #endif
 133  136          haveanswer = 0;
 134  137          while (--ancount >= 0 && cp < eom && haveanswer < MAXADDRS) {
 135      -                if ((n = dn_expand((char *)answer->buf, eom,
 136      -                                                cp, bp, buflen)) < 0)
      138 +                if ((n = dn_expand(answer->buf, eom,
      139 +                    cp, (u_char *)bp, buflen)) < 0)
 137  140                          break;
 138  141                  cp += n;
 139  142                  type = _getshort(cp);
 140  143                  cp += sizeof (u_short);
 141  144                  class = _getshort(cp);
 142  145                  cp += sizeof (u_short) + sizeof (u_long);
 143  146                  n = _getshort(cp);
 144  147                  cp += sizeof (u_short);
 145  148                  if (type == T_CNAME) {
 146  149                          cp += n;
 147  150                          if (ap >= &host_aliases[MAXALIASES-1])
 148  151                                  continue;
 149  152                          *ap++ = bp;
 150  153                          n = strlen(bp) + 1;
 151  154                          bp += n;
 152  155                          buflen -= n;
 153  156                          continue;
 154  157                  }
 155  158                  if (iquery && type == T_PTR) {
 156      -                        if ((n = dn_expand((char *)answer->buf, eom,
 157      -                                        cp, bp, buflen)) < 0) {
      159 +                        if ((n = dn_expand(answer->buf, eom,
      160 +                            cp, (u_char *)bp, buflen)) < 0) {
 158  161                                  cp += n;
 159  162                                  continue;
 160  163                          }
 161  164                          cp += n;
 162  165                          host.h_name = bp;
 163  166                          return (&host);
 164  167                  }
 165  168                  if (iquery || type != T_A) {
 166  169  #ifdef DEBUG
 167  170                          if (_res.options & RES_DEBUG)
↓ open down ↓ 56 lines elided ↑ open up ↑
 224  227  
 225  228  static struct hostent *_gethtbyname();
 226  229  
 227  230  struct hostent *
 228  231  res_gethostbyname(name)
 229  232          char *name;
 230  233  {
 231  234          querybuf buf;
 232  235          register char *cp;
 233  236          int n;
 234      -        struct hostent *hp, *gethostdomain();
 235  237  
 236  238          /*
 237  239           * disallow names consisting only of digits/dots, unless
 238  240           * they end in a dot.
 239  241           */
 240  242          if (isdigit(name[0]))
 241  243                  for (cp = name; /*EMPTY*/; ++cp) {
 242  244                          if (!*cp) {
 243  245                                  if (*--cp == '.')
 244  246                                          break;
↓ open down ↓ 29 lines elided ↑ open up ↑
 274  276          register struct hostent *hp;
 275  277          char qbuf[MAXDNAME];
 276  278  
 277  279          if (type != AF_INET)
 278  280                  return ((struct hostent *) NULL);
 279  281          (void) sprintf(qbuf, "%d.%d.%d.%d.in-addr.arpa",
 280  282                  ((unsigned)addr[3] & 0xff),
 281  283                  ((unsigned)addr[2] & 0xff),
 282  284                  ((unsigned)addr[1] & 0xff),
 283  285                  ((unsigned)addr[0] & 0xff));
 284      -        n = res_query(qbuf, C_IN, T_PTR, (char *)&buf, sizeof (buf));
      286 +        n = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof (buf));
 285  287          if (n < 0) {
 286  288  #ifdef DEBUG
 287  289                  if (_res.options & RES_DEBUG)
 288  290                          printf("res_query failed\n");
 289  291  #endif
 290  292                  if (errno == ECONNREFUSED)
 291  293                          return (_gethtbyaddr(addr, len, type));
 292  294                  return ((struct hostent *) NULL);
 293  295          }
 294  296          hp = getanswer(&buf, n, 1);
↓ open down ↓ 180 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX