[systemd-commits] 2 commits - src/nss-resolve src/resolve
Lennart Poettering
lennart at kemper.freedesktop.org
Fri Jul 18 12:03:31 PDT 2014
src/nss-resolve/nss-resolve.c | 4 ++--
src/resolve/resolved-bus.c | 4 ++--
src/resolve/resolved-dns-cache.c | 19 +++++++++++++++----
3 files changed, 19 insertions(+), 8 deletions(-)
New commits:
commit cbd4560ea2c9f0ae77df1fc64685ff4e559810b6
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Jul 18 21:01:22 2014 +0200
resolved: various bad memory access fixes to the cache
diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c
index 7093b5a..ce74a81 100644
--- a/src/resolve/resolved-dns-cache.c
+++ b/src/resolve/resolved-dns-cache.c
@@ -21,7 +21,10 @@
#include "resolved-dns-cache.h"
+/* Never cache more than 1K entries */
#define CACHE_MAX 1024
+
+/* We never keep any item longer than 10min in our cache */
#define CACHE_TTL_MAX_USEC (10 * USEC_PER_MINUTE)
static void dns_cache_item_free(DnsCacheItem *i) {
@@ -79,7 +82,7 @@ void dns_cache_remove(DnsCache *c, DnsResourceKey *key) {
assert(c);
assert(key);
- while ((i = hashmap_get(c->rrsets, &key)))
+ while ((i = hashmap_get(c->rrsets, key)))
dns_cache_item_remove_and_free(c, i);
}
@@ -105,6 +108,10 @@ static void dns_cache_make_space(DnsCache *c, unsigned add) {
break;
i = prioq_peek(c->expire);
+ assert(i);
+
+ /* Take an extra reference to the RR so that the key
+ * doesn't go away in the middle of the remove call */
rr = dns_resource_record_ref(i->rr);
dns_cache_remove(c, &rr->key);
}
@@ -118,6 +125,7 @@ void dns_cache_prune(DnsCache *c) {
/* Remove all entries that are past their TTL */
for (;;) {
+ _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
DnsCacheItem *i;
usec_t ttl;
@@ -135,7 +143,10 @@ void dns_cache_prune(DnsCache *c) {
if (i->timestamp + ttl > t)
break;
- dns_cache_remove(c, &i->rr->key);
+ /* Take an extra reference to the RR so that the key
+ * doesn't go away in the middle of the remove call */
+ rr = dns_resource_record_ref(i->rr);
+ dns_cache_remove(c, &rr->key);
}
}
@@ -165,11 +176,11 @@ static void dns_cache_item_update(DnsCache *c, DnsCacheItem *i, DnsResourceRecor
assert_se(hashmap_replace(c->rrsets, &rr->key, i) >= 0);
}
+ dns_resource_record_ref(rr);
dns_resource_record_unref(i->rr);
- i->rr = dns_resource_record_ref(rr);
+ i->rr = rr;
i->timestamp = timestamp;
-
prioq_reshuffle(c->expire, i, &i->expire_prioq_idx);
}
commit 878cd63db2d6cfc00ae4d68355a2d5402cd9f24f
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Jul 18 21:01:07 2014 +0200
resolved: fix bus signatures to follow family as int change
diff --git a/src/nss-resolve/nss-resolve.c b/src/nss-resolve/nss-resolve.c
index c172022..5268fb7 100644
--- a/src/nss-resolve/nss-resolve.c
+++ b/src/nss-resolve/nss-resolve.c
@@ -131,7 +131,7 @@ enum nss_status _nss_resolve_gethostbyname4_r(
if (r < 0)
goto fail;
- r = sd_bus_message_append(req, "sy", name, AF_UNSPEC);
+ r = sd_bus_message_append(req, "si", name, AF_UNSPEC);
if (r < 0)
goto fail;
@@ -297,7 +297,7 @@ enum nss_status _nss_resolve_gethostbyname3_r(
if (r < 0)
goto fail;
- r = sd_bus_message_append(req, "sy", name, af);
+ r = sd_bus_message_append(req, "si", name, af);
if (r < 0)
goto fail;
diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c
index 11d94af..5222cc8 100644
--- a/src/resolve/resolved-bus.c
+++ b/src/resolve/resolved-bus.c
@@ -446,8 +446,8 @@ static int bus_method_resolve_address(sd_bus *bus, sd_bus_message *message, void
static const sd_bus_vtable resolve_vtable[] = {
SD_BUS_VTABLE_START(0),
- SD_BUS_METHOD("ResolveHostname", "sy", "a(yayi)s", bus_method_resolve_hostname, SD_BUS_VTABLE_UNPRIVILEGED),
- SD_BUS_METHOD("ResolveAddress", "yayi", "as", bus_method_resolve_address, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("ResolveHostname", "si", "a(iayi)s", bus_method_resolve_hostname, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("ResolveAddress", "iayi", "as", bus_method_resolve_address, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END,
};
More information about the systemd-commits
mailing list