Commit Diff
Diff:
824179e5413293236b6e46167371bdd7023eeb4a
143ed4691308e2cef6a60311881890233508bc78
Commit:
143ed4691308e2cef6a60311881890233508bc78
Tree:
b633421eb2b2236078f1b8fca4bd70aee8f94286
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Wed Jun 17 12:18:53 2015 UTC
Message:
* fix axfr's I think we're ready to start testing on freebsd * work around a double free() -> if (address) { free(address); address = NULL; }
blob - 230fe6c3ac2bccd7eddc8d9fdb89420653db2496
blob + 5ce6b2d0ac34834c5ff92a64de7948e531aeeb01
--- axfr.c
+++ axfr.c
@@ -100,7 +100,7 @@ static struct notifyentry {
} *notn2, *notnp;
-static const char rcsid[] = "$Id: axfr.c,v 1.3 2015/06/17 06:45:09 pjp Exp $";
+static const char rcsid[] = "$Id: axfr.c,v 1.4 2015/06/17 12:18:53 pjp Exp $";
/*
* INIT_AXFR - initialize the axfr singly linked list
@@ -737,15 +737,15 @@ axfr_connection(int so, char *address, int is_ipv6, DB
odh = (struct dns_header *)(reply + 2);
+ q = question->hdr->name;
+ qlen = question->hdr->namelen;
+
rs = get_record_size(db, q, qlen);
if (rs < 0) {
dolog(LOG_INFO, "internal error: %s\n", strerror(errno));
goto drop;
}
- q = question->hdr->name;
- qlen = question->hdr->namelen;
-
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
@@ -911,7 +911,10 @@ axfr_connection(int so, char *address, int is_ipv6, DB
build_reply(&sreply, so, (p + 2), dnslen, fq, NULL, 0, nsdomain, NULL, 0xff, 1, 0, NULL);
outlen = create_anyreply(&sreply, (reply + 2), 65535, outlen, 0);
- free(nsdomain);
+ if (nsdomain) {
+ free(nsdomain);
+ nsdomain = NULL;
+ }
free_question(fq);
} /* for (i.. */
@@ -945,10 +948,14 @@ axfr_connection(int so, char *address, int is_ipv6, DB
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
- if (sdomain)
+ if (sdomain) {
free(sdomain);
- if (savesd)
+ sdomain = NULL;
+ }
+ if (savesd) {
free(savesd);
+ savesd = NULL;
+ }
} while (cursor->c_get(cursor, &key, &data, DB_NEXT) == 0);
cursor->c_close(cursor);
@@ -976,17 +983,25 @@ axfr_connection(int so, char *address, int is_ipv6, DB
drop:
- if (soa)
+ if (soa) {
free (soa);
+ soa = NULL;
+ }
- if (sdomain)
+ if (sdomain) {
free (sdomain);
+ sdomain = NULL;
+ }
- if (nsdomain)
+ if (nsdomain) {
free (nsdomain);
+ nsdomain = NULL;
+ }
- if (savesd)
+ if (savesd) {
free (savesd);
+ savesd = NULL;
+ }
close(so);
exit(0);
@@ -1166,9 +1181,10 @@ build_soa(DB *db, char *reply, int offset, struct doma
int
checklabel(DB *db, struct domain *sd, struct domain *soa, struct question *q)
{
- struct domain tmpsd;
+ struct domain *tmpsd;
char *p;
int plen, ret;
+ int rs;
DBT key, data;
@@ -1182,6 +1198,16 @@ checklabel(DB *db, struct domain *sd, struct domain *s
if (*p == '\0')
return (0);
+ rs = get_record_size(db, p, plen);
+ if (rs < 0) {
+ return (0);
+ }
+
+ tmpsd = calloc(1, rs);
+ if (tmpsd == NULL) {
+ return (0);
+ }
+
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
@@ -1189,30 +1215,34 @@ checklabel(DB *db, struct domain *sd, struct domain *s
key.size = plen;
data.data = NULL;
- data.size = 0;
+ data.size = rs;
ret = db->get(db, NULL, &key, &data, 0);
if (ret == DB_NOTFOUND) {
plen -= (*p + 1);
p = (p + (*p + 1));
+ free(tmpsd);
continue;
}
- if (data.size != sizeof(struct domain)) {
+ if (data.size != rs) {
dolog(LOG_INFO, "AXFR btree db is damaged (%d), drop\n", __LINE__);
+ free(tmpsd);
return (0);
}
- memcpy(&tmpsd, data.data, sizeof(tmpsd));
+ memcpy(tmpsd, data.data, data.size);
/*
* the encountered label has an SOA before we got to the
* root, so we skip this record entirely...
*/
- if (tmpsd.flags & DOMAIN_HAVE_SOA)
+ if (tmpsd->flags & DOMAIN_HAVE_SOA) {
+ free (tmpsd);
return (0);
+ }
/*
@@ -1222,6 +1252,7 @@ checklabel(DB *db, struct domain *sd, struct domain *s
plen -= (*p + 1);
p = (p + (*p + 1));
+ free(tmpsd);
} while (memcmp(p, q->hdr->name, q->hdr->namelen) != 0);
blob - 538becce9099322c2643b600b8eb2e6b7d84e37f
blob + 0b5ac4b5cac56834dbb6a103c1387dc84660edf3
--- main.c
+++ main.c
@@ -174,7 +174,7 @@ static struct tcps {
} *tn1, *tnp, *tntmp;
-static const char rcsid[] = "$Id: main.c,v 1.5 2015/06/17 11:44:39 pjp Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.6 2015/06/17 12:18:53 pjp Exp $";
/*
* MAIN - set up arguments, set up database, set up sockets, call mainloop
@@ -3640,6 +3640,7 @@ get_record_size(DB *db, char *converted_name, int conv
{
struct domain *sdomain;
DBT key, data;
+ int ret;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
@@ -3650,11 +3651,11 @@ get_record_size(DB *db, char *converted_name, int conv
data.data = NULL;
data.size = sizeof(struct domain);
- if (db->get(db, NULL, &key, &data, 0) == 0) {
+ if ((ret = db->get(db, NULL, &key, &data, 0)) == 0) {
sdomain = (struct domain *)data.data;
return (sdomain->len);
} else {
- if (debug)
+ if (debug && ret != DB_NOTFOUND )
dolog(LOG_INFO, "db->get: %s\n", strerror(errno));
}
repomaster@centroid.eu