File avahi-packet-add-probe-query-fix-size-compare.patch of Package avahi

Index: avahi-0.6.23/avahi-core/probe-sched.c
===================================================================
--- avahi-0.6.23.orig/avahi-core/probe-sched.c
+++ avahi-0.6.23/avahi-core/probe-sched.c
@@ -181,7 +181,7 @@ static int packet_add_probe_query(AvahiP
         avahi_record_get_estimate_size(pj->record);
 
     /* Too large */
-    if (size > avahi_dns_packet_space(p))
+    if (size > avahi_dns_packet_reserved_space(p))
         return 0;
 
     /* Create the probe query */
@@ -191,6 +191,9 @@ static int packet_add_probe_query(AvahiP
     b = !!avahi_dns_packet_append_key(p, k, 0);
     assert(b);
 
+    /* reserve size for record data */
+    avahi_dns_packet_reserve_size(p, avahi_record_get_estimate_size(pj->record));
+
     /* Mark this job for addition to the packet */
     pj->chosen = 1;
 
@@ -204,9 +207,12 @@ static int packet_add_probe_query(AvahiP
             continue;
         
         /* This job wouldn't fit in */
-        if (avahi_record_get_estimate_size(pj->record) > avahi_dns_packet_space(p))
+        if (avahi_record_get_estimate_size(pj->record) > avahi_dns_packet_reserved_space(p))
             break;
 
+	/* reserve size for record data */
+    	avahi_dns_packet_reserve_size(p, avahi_record_get_estimate_size(pj->record));
+
         /* Mark this job for addition to the packet */
         pj->chosen = 1;
     }
Index: avahi-0.6.23/avahi-core/dns.c
===================================================================
--- avahi-0.6.23.orig/avahi-core/dns.c
+++ avahi-0.6.23/avahi-core/dns.c
@@ -57,6 +57,7 @@ AvahiDnsPacket* avahi_dns_packet_new(uns
     
     p->size = p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE;
     p->max_size = max_size;
+    p->res_size = 0;
     p->name_table = NULL;
     p->data = NULL;
 
@@ -835,6 +836,25 @@ size_t avahi_dns_packet_space(AvahiDnsPa
     return p->max_size - p->size;
 }
 
+size_t avahi_dns_packet_reserve_size(AvahiDnsPacket *p, size_t res_size) {
+    assert(p);
+
+    assert(p->size + p->res_size <= p->max_size);
+
+    if ((p->size + p->res_size + res_size) <= p->max_size)
+	p->res_size += res_size;
+
+    return p->res_size;
+}
+
+size_t avahi_dns_packet_reserved_space(AvahiDnsPacket *p) {
+    assert(p);
+
+    assert(p->size + p->res_size <= p->max_size);
+
+    return p->max_size - p->size - p->res_size;
+}
+
 int avahi_rdata_parse(AvahiRecord *record, const void* rdata, size_t size) {
     int ret;
     AvahiDnsPacket p;
Index: avahi-0.6.23/avahi-core/dns.h
===================================================================
--- avahi-0.6.23.orig/avahi-core/dns.h
+++ avahi-0.6.23/avahi-core/dns.h
@@ -32,7 +32,7 @@
 #define AVAHI_DNS_PACKET_SIZE_MAX (AVAHI_DNS_PACKET_HEADER_SIZE + 256 + 2 + 2 + 4 + 2 + AVAHI_DNS_RDATA_MAX)
 
 typedef struct AvahiDnsPacket {
-    size_t size, rindex, max_size;
+    size_t size, rindex, max_size, res_size;
     AvahiHashmap *name_table; /* for name compression */
     uint8_t *data;
 } AvahiDnsPacket;
@@ -80,6 +80,8 @@ int avahi_dns_packet_skip(AvahiDnsPacket
 
 int avahi_dns_packet_is_empty(AvahiDnsPacket *p);
 size_t avahi_dns_packet_space(AvahiDnsPacket *p);
+size_t avahi_dns_packet_reserve_size(AvahiDnsPacket *p, size_t res_size);
+size_t avahi_dns_packet_reserved_space(AvahiDnsPacket *p);
 
 #define AVAHI_DNS_FIELD_ID 0
 #define AVAHI_DNS_FIELD_FLAGS 1