Blame ares_expand_string.c

Packit 514978
Packit 514978
/* Copyright 1998 by the Massachusetts Institute of Technology.
Packit 514978
 *
Packit 514978
 * Permission to use, copy, modify, and distribute this
Packit 514978
 * software and its documentation for any purpose and without
Packit 514978
 * fee is hereby granted, provided that the above copyright
Packit 514978
 * notice appear in all copies and that both that copyright
Packit 514978
 * notice and this permission notice appear in supporting
Packit 514978
 * documentation, and that the name of M.I.T. not be used in
Packit 514978
 * advertising or publicity pertaining to distribution of the
Packit 514978
 * software without specific, written prior permission.
Packit 514978
 * M.I.T. makes no representations about the suitability of
Packit 514978
 * this software for any purpose.  It is provided "as is"
Packit 514978
 * without express or implied warranty.
Packit 514978
 */
Packit 514978
Packit 514978
#include "ares_setup.h"
Packit 514978
Packit 514978
#ifdef HAVE_NETINET_IN_H
Packit 514978
#  include <netinet/in.h>
Packit 514978
#endif
Packit 514978
#ifdef HAVE_ARPA_NAMESER_H
Packit 514978
#  include <arpa/nameser.h>
Packit 514978
#else
Packit 514978
#  include "nameser.h"
Packit 514978
#endif
Packit 514978
Packit 514978
#include "ares.h"
Packit 514978
#include "ares_private.h" /* for the memdebug */
Packit 514978
Packit 514978
/* Simply decodes a length-encoded character string. The first byte of the
Packit 514978
 * input is the length of the string to be returned and the bytes thereafter
Packit 514978
 * are the characters of the string. The returned result will be NULL
Packit 514978
 * terminated.
Packit 514978
 */
Packit 514978
int ares_expand_string(const unsigned char *encoded,
Packit 514978
                       const unsigned char *abuf,
Packit 514978
                       int alen,
Packit 514978
                       unsigned char **s,
Packit 514978
                       long *enclen)
Packit 514978
{
Packit 514978
  unsigned char *q;
Packit 514978
  union {
Packit 514978
    ares_ssize_t sig;
Packit 514978
     size_t uns;
Packit 514978
  } elen;
Packit 514978
Packit 514978
  if (encoded == abuf+alen)
Packit 514978
    return ARES_EBADSTR;
Packit 514978
Packit 514978
  elen.uns = *encoded;
Packit 514978
  if (encoded+elen.sig+1 > abuf+alen)
Packit 514978
    return ARES_EBADSTR;
Packit 514978
Packit 514978
  encoded++;
Packit 514978
Packit 514978
  *s = ares_malloc(elen.uns+1);
Packit 514978
  if (*s == NULL)
Packit 514978
    return ARES_ENOMEM;
Packit 514978
  q = *s;
Packit 514978
  strncpy((char *)q, (char *)encoded, elen.uns);
Packit 514978
  q[elen.uns] = '\0';
Packit 514978
Packit 514978
  *s = q;
Packit 514978
Packit 514978
  *enclen = (long)(elen.sig+1);
Packit 514978
Packit 514978
  return ARES_SUCCESS;
Packit 514978
}
Packit 514978