]> git.meshlink.io Git - catta/commitdiff
* Patch from Sjoerd Simons - if we shorten a DNS packet to remove records, we must...
authorTrent Lloyd <lathiat@bur.st>
Sat, 7 Jul 2007 21:22:19 +0000 (21:22 +0000)
committerTrent Lloyd <lathiat@bur.st>
Sat, 7 Jul 2007 21:22:19 +0000 (21:22 +0000)
the removed section.  Add avahi_dns_packet_cleanup_name_table and call in appropriate places where packet is shrunk.

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1493 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-core/dns.c
avahi-core/dns.h

index 0206ec767271227fb37fb0ad85daa937b3e69d55..34a3279dff97a19dd06a4f83fce1c0316023fe81 100644 (file)
@@ -153,6 +153,22 @@ void avahi_dns_packet_inc_field(AvahiDnsPacket *p, unsigned idx) {
     avahi_dns_packet_set_field(p, idx, avahi_dns_packet_get_field(p, idx) + 1);
 }   
 
+
+static void
+name_table_cleanup(void *key, void *value, void *user_data) {
+  AvahiDnsPacket *p = (AvahiDnsPacket *)user_data;
+
+  if ((uint8_t *)value >= AVAHI_DNS_PACKET_DATA(p) + p->size) {
+    avahi_hashmap_remove(p->name_table, key);
+  }
+}
+
+void
+avahi_dns_packet_cleanup_name_table(AvahiDnsPacket *p) {
+  if (p->name_table)
+    avahi_hashmap_foreach(p->name_table, name_table_cleanup, p);
+}
+
 uint8_t* avahi_dns_packet_append_name(AvahiDnsPacket *p, const char *name) {
     uint8_t *d, *saved_ptr = NULL;
     size_t saved_size;
@@ -216,6 +232,8 @@ uint8_t* avahi_dns_packet_append_name(AvahiDnsPacket *p, const char *name) {
 
 fail:
     p->size = saved_size;
+    avahi_dns_packet_cleanup_name_table(p);
+
     return NULL;
 }
 
@@ -685,6 +703,8 @@ uint8_t* avahi_dns_packet_append_key(AvahiDnsPacket *p, AvahiKey *k, int unicast
         !avahi_dns_packet_append_uint16(p, k->type) ||
         !avahi_dns_packet_append_uint16(p, k->clazz | (unicast_response ? AVAHI_DNS_UNICAST_RESPONSE : 0))) {
         p->size = size;
+        avahi_dns_packet_cleanup_name_table(p);
+
         return NULL;
     }
 
@@ -799,6 +819,8 @@ uint8_t* avahi_dns_packet_append_record(AvahiDnsPacket *p, AvahiRecord *r, int c
 
 fail:
     p->size = size;
+    avahi_dns_packet_cleanup_name_table(p);
+
     return NULL;
 }
 
index d4855100988f771776ac57de1b4af3da7772545c..7ec9935e40602d019755b55ff94ffebf3c86094b 100644 (file)
@@ -52,6 +52,8 @@ void avahi_dns_packet_inc_field(AvahiDnsPacket *p, unsigned idx);
 
 uint8_t *avahi_dns_packet_extend(AvahiDnsPacket *p, size_t l);
 
+void avahi_dns_packet_cleanup_name_table(AvahiDnsPacket *p);
+
 uint8_t *avahi_dns_packet_append_uint16(AvahiDnsPacket *p, uint16_t v);
 uint8_t *avahi_dns_packet_append_uint32(AvahiDnsPacket *p, uint32_t v);
 uint8_t *avahi_dns_packet_append_name(AvahiDnsPacket *p, const char *name);