Commit ffdd3bc8 authored by Mark Andrews's avatar Mark Andrews
Browse files

4231. [contrib] Address unchecked memory allocation calls in

                        query-loc and zone2ldap. [RT #40789]
parent 09f4e419
4231. [contrib] Address unchecked memory allocation calls in
query-loc and zone2ldap. [RT #40789]
4231. [contrib] Address unchecked calloc call in dlz_mysqldyn_mod.c.
[RT #40840]
......
/* config.h.in. Generated from configure.in by autoheader. */
/* $Id: config.h.in,v 1.1 2008/02/15 01:47:15 marka Exp $ */
/* Define to 1 if you have the <arpa/nameser_compat.h> header file. */
#undef HAVE_ARPA_NAMESER_COMPAT_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
......@@ -8,6 +9,9 @@
/* Define to 1 if you have the `resolv' library (-lresolv). */
#undef HAVE_LIBRESOLV
/* Is there a loc_ntoa on this system? */
#undef HAVE_LOC_NTOA
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
......@@ -44,19 +48,22 @@
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of a `char', as computed by sizeof. */
/* The size of `char', as computed by sizeof. */
#undef SIZEOF_CHAR
/* The size of a `int', as computed by sizeof. */
/* The size of `int', as computed by sizeof. */
#undef SIZEOF_INT
/* The size of a `long', as computed by sizeof. */
/* The size of `long', as computed by sizeof. */
#undef SIZEOF_LONG
/* The size of a `short', as computed by sizeof. */
/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT
/* Define to 1 if you have the ANSI C header files. */
......@@ -64,6 +71,3 @@
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Is there a loc_ntoa on this system? */
#undef HAVE_LOC_NTOA
This diff is collapsed.
......@@ -17,6 +17,7 @@ AC_HEADER_STDC
AC_CONFIG_HEADER(config.h)
AC_CHECK_HEADER(resolv.h, , AC_MSG_ERROR("No headers for name service applications"))
AC_CHECK_HEADER(arpa/nameser.h, , AC_MSG_ERROR("No headers for name service applications"))
AC_CHECK_HEADERS(arpa/nameser_compat.h)
AC_CHECK_HEADER(sys/time.h, , AC_MSG_ERROR("Mandatory header missing on your system"))
AC_CHECK_HEADER(unistd.h, , AC_MSG_ERROR("Mandatory header missing on your system"))
......@@ -26,29 +27,32 @@ AC_MSG_CHECKING(if libnsl is mandatory)
AC_TRY_LINK([#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
#include <arpa/nameser_compat.h>
#endif
#include <resolv.h>
union
{
HEADER hdr;
HEADER hdr;
u_char buf[4096]; /* With RFC 2671, otherwise 512 is enough */
}
response;
char *domain;
int requested_type; ],
int requested_type; ],
[res_query(domain,
C_IN,
requested_type,
(u_char *) & response,
sizeof (response)) ], dnl
[AC_MSG_RESULT(no)], dnl
[AC_MSG_RESULT(yes); LIBS="${LIBS} -lnsl"])
C_IN,
requested_type,
(u_char *) & response,
sizeof (response)) ],
[AC_MSG_RESULT(no)],
[AC_MSG_RESULT(yes); LIBS="${LIBS} -lnsl"])
dnl Check for the loc_ntoa macro/function
AC_MSG_CHECKING(loc_ntoa)
AC_TRY_LINK([#include <resolv.h>], dnl
[u_char *cp; char *result; loc_ntoa(cp, result)], dnl
[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_LOC_NTOA)], dnl
[AC_MSG_RESULT([no, using the alternative]); LOC_NTOA=loc_ntoa.o])
AC_TRY_LINK([#include <resolv.h>],
[u_char *cp; char *result; loc_ntoa(cp, result)],
[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_LOC_NTOA,,[Is there a loc_ntoa on this system?])],
[AC_MSG_RESULT([no, using the alternative]); LOC_NTOA=loc_ntoa.o])
AC_SUBST(LOC_NTOA)
dnl Checks for typedefs, structures, and compiler characteristics.
......@@ -60,6 +64,3 @@ AC_CHECK_SIZEOF(char)
dnl Misc.
AC_OUTPUT(Makefile)
......@@ -367,6 +367,10 @@ int responseLen; /* buffer length */
result = (char *) malloc (256);
message = (char *) malloc (256);
if (result == NULL || message == NULL)
{
panic ("Malloc failed");
}
/*
* Look up the records for the given domain name.
* We expect the domain to be a fully qualified name, so
......@@ -569,6 +573,10 @@ findA (domain)
if (end == NULL)
{
result = (void *) malloc (sizeof (struct list_in_addr));
if (result == NULL)
{
panic ("Malloc failed");
}
result->addr = addr;
result->next = NULL;
end = result;
......@@ -576,6 +584,10 @@ findA (domain)
else
{
end->next = (void *) malloc (sizeof (struct list_in_addr));
if (end->next == NULL)
{
panic ("Malloc failed");
}
end = end->next;
end->addr = addr;
end->next = NULL;
......
......@@ -18,6 +18,9 @@
#include <string.h>
#include <signal.h>
#include <arpa/nameser.h>
#ifdef HAVE_ARPA_NAMESER_COMPAT_H
#include <arpa/nameser_compat.h>
#endif
#include <resolv.h>
#ifndef FALSE
......
......@@ -2,8 +2,8 @@ INSTALLATION
To Compile zone2ldap from contrib/sdb directory:
gcc -g `../../isc-config.sh --cflags isc dns` -c zone2ldap.c
gcc -g -o zone2ldap zone2ldap.o `isc-config.sh --libs isc dns` -lldap -llber -lresolv
gcc -g `../../../isc-config.sh --cflags isc dns` -c zone2ldap.c
gcc -g -o zone2ldap zone2ldap.o `../../../isc-config.sh --libs isc dns` -lldap -llber -lresolv
USAGE:
......
......@@ -4,7 +4,7 @@
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
*
* Change Log
*
* Tue May 1 19:19:54 EDT 2001 - Jeff McNeil
......@@ -36,6 +36,8 @@
#include <dns/result.h>
#include <dns/rdatatype.h>
#define LDAP_DEPRECATED 1
#include <ldap.h>
#define DNS_OBJECT 6
......@@ -43,7 +45,7 @@
#define VERSION "0.4-ALPHA"
#define NO_SPEC 0
#define NO_SPEC 0
#define WI_SPEC 1
/* Global Zone Pointer */
......@@ -105,8 +107,16 @@ unsigned int debug = 0;
debug = 1;
#endif
static void
fatal(const char *msg) {
perror(msg);
if (conn != NULL)
ldap_unbind_s(conn);
exit(1);
}
int
main (int *argc, char **argv)
main (int argc, char **argv)
{
isc_mem_t *mctx = NULL;
isc_entropy_t *ectx = NULL;
......@@ -133,13 +143,13 @@ main (int *argc, char **argv)
int create_base = 0;
int topt;
if ((int) argc < 2)
if (argc < 2)
{
usage ();
exit (-1);
}
while ((topt = getopt ((int) argc, argv, "D:w:b:z:f:h:?dcv")) != -1)
while ((topt = getopt (argc, argv, "D:w:b:z:f:h:?dcv")) != -1)
{
switch (topt)
{
......@@ -154,23 +164,35 @@ main (int *argc, char **argv)
break;
case 'D':
binddn = strdup (optarg);
if (binddn == NULL)
fatal("strdup");
break;
case 'w':
bindpw = strdup (optarg);
if (bindpw == NULL)
fatal("strdup");
break;
case 'b':
ldapbase = strdup (optarg);
if (ldapbase == NULL)
fatal("strdup");
break;
case 'z':
argzone = strdup (optarg);
// We wipe argzone all to hell when we parse it for the DN */
gbl_zone = strdup(argzone);
if (argzone == NULL || gbl_zone == NULL)
fatal("strdup");
break;
case 'f':
zonefile = strdup (optarg);
if (zonefile == NULL)
fatal("strdup");
break;
case 'h':
ldapsystem = strdup (optarg);
if (ldapsystem == NULL)
fatal("strdup");
break;
case '?':
default:
......@@ -354,10 +376,10 @@ isc_result_check (isc_result_t res, char *errorstr)
void
generate_ldap (dns_name_t * dnsname, dns_rdata_t * rdata, unsigned int ttl)
{
unsigned char name[DNS_NAME_MAXTEXT + 1];
char name[DNS_NAME_MAXTEXT + 1];
unsigned int len;
unsigned char type[20];
unsigned char data[2048];
char type[20];
char data[2048];
char **dc_list;
char *dn;
......@@ -412,7 +434,7 @@ locate_by_dn (char *dn)
* calloc a LDAPMod array, fill in the default "everyone needs this" information,
* including object classes and dc's. If it locate_by_dn does return, then we'll
* realloc for more LDAPMod structs, and appened the new data. If an LDAPMod exists
* for the parameter we're adding, then we'll realloc the mod_values array, and
* for the parameter we're adding, then we'll realloc the mod_values array, and
* add the new value to the existing LDAPMod. Finnaly, it assures linkage exists
* within the Run queue linked ilst*/
......@@ -436,29 +458,21 @@ add_to_rr_list (char *dn, char *name, char *type,
tmp = (ldap_info *) malloc (sizeof (ldap_info));
if (tmp == (ldap_info *) NULL)
{
fprintf (stderr, "malloc: %s\n", strerror (errno));
ldap_unbind_s (conn);
exit (-1);
}
fatal("malloc");
tmp->dn = strdup (dn);
if (tmp->dn == NULL)
fatal("strdup");
tmp->attrs = (LDAPMod **) calloc (sizeof (LDAPMod *), flags);
if (tmp->attrs == (LDAPMod **) NULL)
{
fprintf (stderr, "calloc: %s\n", strerror (errno));
ldap_unbind_s (conn);
exit (-1);
}
fatal("calloc");
for (i = 0; i < flags; i++)
{
tmp->attrs[i] = (LDAPMod *) malloc (sizeof (LDAPMod));
if (tmp->attrs[i] == (LDAPMod *) NULL)
{
fprintf (stderr, "malloc: %s\n", strerror (errno));
exit (-1);
}
fatal("malloc");
}
tmp->attrs[0]->mod_op = LDAP_MOD_ADD;
tmp->attrs[0]->mod_type = "objectClass";
......@@ -480,37 +494,51 @@ add_to_rr_list (char *dn, char *name, char *type,
tmp->attrs[1]->mod_values = (char **) calloc (sizeof (char *), 2);
if (tmp->attrs[1]->mod_values == (char **)NULL)
exit(-1);
fatal("calloc");
tmp->attrs[1]->mod_values[0] = strdup (name);
tmp->attrs[1]->mod_values[2] = NULL;
if (tmp->attrs[1]->mod_values[0] == NULL)
fatal("strdup");
sprintf (ldap_type_buffer, "%sRecord", type);
tmp->attrs[2]->mod_op = LDAP_MOD_ADD;
tmp->attrs[2]->mod_type = strdup (ldap_type_buffer);
tmp->attrs[2]->mod_values = (char **) calloc (sizeof (char *), 2);
if (tmp->attrs[2]->mod_values == (char **)NULL)
exit(-1);
if (tmp->attrs[2]->mod_type == NULL ||
tmp->attrs[2]->mod_values == (char **)NULL)
fatal("strdup/calloc");
tmp->attrs[2]->mod_values[0] = strdup (data);
tmp->attrs[2]->mod_values[1] = NULL;
if (tmp->attrs[2]->mod_values[0] == NULL)
fatal("strdup");
tmp->attrs[3]->mod_op = LDAP_MOD_ADD;
tmp->attrs[3]->mod_type = "dNSTTL";
tmp->attrs[3]->mod_values = (char **) calloc (sizeof (char *), 2);
if (tmp->attrs[3]->mod_values == (char **)NULL)
exit(-1);
fatal("calloc");
sprintf (charttl, "%d", ttl);
tmp->attrs[3]->mod_values[0] = strdup (charttl);
tmp->attrs[3]->mod_values[1] = NULL;
if (tmp->attrs[3]->mod_values[0] == NULL)
fatal("strdup");
tmp->attrs[4]->mod_op = LDAP_MOD_ADD;
tmp->attrs[4]->mod_type = "zoneName";
tmp->attrs[4]->mod_values = (char **)calloc(sizeof(char *), 2);
if (tmp->attrs[4]->mod_values == (char **)NULL)
fatal("calloc");
tmp->attrs[4]->mod_values[0] = gbl_zone;
tmp->attrs[4]->mod_values[1] = NULL;
......@@ -535,15 +563,15 @@ add_to_rr_list (char *dn, char *name, char *type,
sizeof (char *) * (attrlist + 1));
if (tmp->attrs[i]->mod_values == (char **) NULL)
{
fprintf (stderr, "realloc: %s\n", strerror (errno));
ldap_unbind_s (conn);
exit (-1);
}
fatal("realloc");
for (x = 0; tmp->attrs[i]->mod_values[x] != NULL; x++);
tmp->attrs[i]->mod_values[x] = strdup (data);
if (tmp->attrs[i]->mod_values[x] == NULL)
fatal("strdup");
tmp->attrs[i]->mod_values[x + 1] = NULL;
return;
}
}
......@@ -551,18 +579,23 @@ add_to_rr_list (char *dn, char *name, char *type,
(LDAPMod **) realloc (tmp->attrs,
sizeof (LDAPMod) * ++(tmp->attrcnt));
if (tmp->attrs == NULL)
{
fprintf (stderr, "realloc: %s\n", strerror (errno));
ldap_unbind_s (conn);
exit (-1);
}
fatal("realloc");
for (x = 0; tmp->attrs[x] != NULL; x++);
tmp->attrs[x] = (LDAPMod *) malloc (sizeof (LDAPMod));
if (tmp->attrs[x] == NULL)
fatal("malloc");
tmp->attrs[x]->mod_op = LDAP_MOD_ADD;
tmp->attrs[x]->mod_type = strdup (ldap_type_buffer);
tmp->attrs[x]->mod_values = (char **) calloc (sizeof (char *), 2);
if (tmp->attrs[x]->mod_type == NULL ||
tmp->attrs[x]->mod_values == (char **)NULL)
fatal("strdup/calloc");
tmp->attrs[x]->mod_values[0] = strdup (data);
if (tmp->attrs[x]->mod_values[0] == NULL)
fatal("strdup");
tmp->attrs[x]->mod_values[1] = NULL;
tmp->attrs[x + 1] = NULL;
}
......@@ -597,6 +630,8 @@ hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
char *hnamebuff;
zname = strdup (hostname);
if (zname == NULL)
fatal("strdup");
if (flags == DNS_OBJECT)
{
......@@ -606,6 +641,8 @@ hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
tmp = &zname[strlen (zname) - strlen (zone)];
*--tmp = '\0';
hnamebuff = strdup (zname);
if (hnamebuff == NULL)
fatal("strdup");
zname = ++tmp;
}
else
......@@ -632,7 +669,7 @@ hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
/* build an sdb compatible LDAP DN from a "dc_list" (char **).
* will append dNSTTL information to each RR Record, with the
* will append dNSTTL information to each RR Record, with the
* exception of "@"/SOA. */
char *
......@@ -663,11 +700,11 @@ build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag)
}
strncat (dn, tmp, sizeof (dn) - strlen (dn));
strlcat (dn, tmp, sizeof (dn));
}
sprintf (tmp, "dc=%s", dc_list[0]);
strncat (dn, tmp, sizeof (dn) - strlen (dn));
strlcat (dn, tmp, sizeof (dn));
fflush(NULL);
return dn;
......@@ -732,5 +769,5 @@ void
usage ()
{
fprintf (stderr,
"zone2ldap -D [BIND DN] -w [BIND PASSWORD] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST]
[-c Create LDAP Base structure][-d Debug Output (lots !)] \n ");}
"zone2ldap -D [BIND DN] -w [BIND PASSWORD] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST] "
"[-c Create LDAP Base structure][-d Debug Output (lots !)] \n ");}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment