]> git.meshlink.io Git - catta/commitdiff
fix some memory corruption bugs
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Apr 2005 17:19:18 +0000 (17:19 +0000)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Apr 2005 17:19:18 +0000 (17:19 +0000)
make use auf SRV registration functions in main.c

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

dns.c
main.c
rr.c
strlst.c
util.c

diff --git a/dns.c b/dns.c
index 776ead24bf9130ab92540287b69103ccf92e7865..9126100ac096b3a8944193651d89950923ab1765 100644 (file)
--- a/dns.c
+++ b/dns.c
@@ -390,7 +390,7 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl
     g_assert(p);
     g_assert(ret_cache_flush);
 
-    g_message("consume_record()");
+/*     g_message("consume_record()"); */
 
     if (flx_dns_packet_consume_name(p, name, sizeof(name)) < 0 ||
         flx_dns_packet_consume_uint16(p, &type) < 0 ||
@@ -401,7 +401,7 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl
         
         goto fail;
 
-    g_message("name = %s, rdlength = %u", name, rdlength);
+/*     g_message("name = %s, rdlength = %u", name, rdlength); */
     
     start = flx_dns_packet_get_rptr(p);
 
@@ -411,7 +411,7 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl
         case FLX_DNS_TYPE_PTR:
         case FLX_DNS_TYPE_CNAME:
 
-            g_message("ptr");
+/*             g_message("ptr"); */
             
             if (flx_dns_packet_consume_name(p, buf, sizeof(buf)) < 0)
                 goto fail;
@@ -422,7 +422,7 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl
             
         case FLX_DNS_TYPE_SRV:
 
-            g_message("srv");
+/*             g_message("srv"); */
             
             if (flx_dns_packet_consume_uint16(p, &r->data.srv.priority) < 0 ||
                 flx_dns_packet_consume_uint16(p, &r->data.srv.weight) < 0 ||
@@ -435,7 +435,7 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl
 
         case FLX_DNS_TYPE_HINFO:
             
-            g_message("hinfo");
+/*             g_message("hinfo"); */
 
             if (flx_dns_packet_consume_string(p, buf, sizeof(buf)) < 0)
                 goto fail;
@@ -450,34 +450,30 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl
 
         case FLX_DNS_TYPE_TXT:
 
-            g_message("txt");
+/*             g_message("txt"); */
 
             if (rdlength > 0) {
                 r->data.txt.string_list = flx_string_list_parse(flx_dns_packet_get_rptr(p), rdlength);
                 
                 if (flx_dns_packet_skip(p, rdlength) < 0)
                     goto fail;
-            }
+            } else
+                r->data.txt.string_list = NULL;
             
             break;
 
         case FLX_DNS_TYPE_A:
 
-            g_message("A");
-
+/*             g_message("A"); */
 
-            g_message("%p", flx_dns_packet_get_rptr(p));
-                
             if (flx_dns_packet_consume_bytes(p, &r->data.a.address, sizeof(flxIPv4Address)) < 0)
                 goto fail;
-
-            g_message("%p", flx_dns_packet_get_rptr(p));
             
             break;
 
         case FLX_DNS_TYPE_AAAA:
 
-            g_message("aaaa");
+/*             g_message("aaaa"); */
             
             if (flx_dns_packet_consume_bytes(p, &r->data.aaaa.address, sizeof(flxIPv6Address)) < 0)
                 goto fail;
@@ -486,7 +482,7 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl
             
         default:
 
-            g_message("generic");
+/*             g_message("generic"); */
             
             if (rdlength > 0) {
 
@@ -499,7 +495,7 @@ flxRecord* flx_dns_packet_consume_record(flxDnsPacket *p, gboolean *ret_cache_fl
             break;
     }
 
-    g_message("%i == %u ?", (guint8*) flx_dns_packet_get_rptr(p) - (guint8*) start, rdlength);
+/*     g_message("%i == %u ?", (guint8*) flx_dns_packet_get_rptr(p) - (guint8*) start, rdlength); */
     
     /* Check if we read enough data */
     if ((guint8*) flx_dns_packet_get_rptr(p) - (guint8*) start != rdlength)
@@ -606,7 +602,7 @@ guint8* flx_dns_packet_append_record(flxDnsPacket *p, flxRecord *r, gboolean cac
 
             size = flx_string_list_serialize(r->data.txt.string_list, NULL, 0);
 
-            g_message("appending string: %u %p", size, r->data.txt.string_list);
+/*             g_message("appending string: %u %p", size, r->data.txt.string_list); */
 
             if (!(data = flx_dns_packet_extend(p, size)))
                 goto fail;
@@ -645,7 +641,7 @@ guint8* flx_dns_packet_append_record(flxDnsPacket *p, flxRecord *r, gboolean cac
     size = flx_dns_packet_extend(p, 0) - start;
     g_assert(size <= 0xFFFF);
 
-    g_message("appended %u", size);
+/*     g_message("appended %u", size); */
 
     * (guint16*) l = g_htons((guint16) size);
     
diff --git a/main.c b/main.c
index 0479f14b56c3ffbe7d59aae5080a7d66c0564e29..3bf4360bc9cad3168437d6bbc7c58058f6a7cf0e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -57,6 +57,7 @@ int main(int argc, char *argv[]) {
     flx = flx_server_new(NULL);
 
     flx_server_add_text(flx, 0, 0, AF_UNSPEC, FALSE, NULL, "hallo", NULL);
+    flx_server_add_service(flx, 0, 0, AF_UNSPEC, "_http._tcp", "gurke", NULL, NULL, 80, "foo", NULL);
 
 /*     k = flx_key_new("ecstasy.local.", FLX_DNS_CLASS_IN, FLX_DNS_TYPE_ANY); */
 /*     s = flx_subscription_new(flx, k, 0, AF_UNSPEC, subscription, NULL); */
diff --git a/rr.c b/rr.c
index a1c5868ce0f980c694b04231b84bf4c9d6325905..fe475eb0e5a58f69ed11cab5d5c0214130802877 100644 (file)
--- a/rr.c
+++ b/rr.c
@@ -241,18 +241,17 @@ guint flx_key_hash(const flxKey *k) {
 }
 
 static gboolean rdata_equal(const flxRecord *a, const flxRecord *b) {
-    gchar *t;
     g_assert(a);
     g_assert(b);
     g_assert(a->key->type == b->key->type);
 
-    t = flx_record_to_string(a);
-    g_message("comparing %s", t);
-    g_free(t);
+/*     t = flx_record_to_string(a); */
+/*     g_message("comparing %s", t); */
+/*     g_free(t); */
 
-    t = flx_record_to_string(b);
-    g_message("and %s", t);
-    g_free(t);
+/*     t = flx_record_to_string(b); */
+/*     g_message("and %s", t); */
+/*     g_free(t); */
 
     
     switch (a->key->type) {
index 8993f3a2920b02b3887c9f6ef1bf5908a27e529d..d0507e0a2458467d67d962c00091c9c34ce117ec 100644 (file)
--- a/strlst.c
+++ b/strlst.c
@@ -206,10 +206,10 @@ flxStringList *flx_string_list_new_va(va_list va) {
 }
 
 flxStringList *flx_string_list_copy(flxStringList *l) {
-    flxStringList *r;
+    flxStringList *r = NULL;
 
     for (; l; l = l->next)
-        r = flx_string_list_add(l, l->text);
+        r = flx_string_list_add(r, l->text);
 
     return string_list_reverse(r);
 }
diff --git a/util.c b/util.c
index 47642e815c8b21436a6850a244ceae824f3b2279..3edaa8878398166b13e36bfc3efdba6a404cabc5 100644 (file)
--- a/util.c
+++ b/util.c
@@ -48,9 +48,11 @@ gint flx_timeval_compare(const GTimeVal *a, const GTimeVal *b) {
 glong flx_timeval_diff(const GTimeVal *a, const GTimeVal *b) {
     g_assert(a);
     g_assert(b);
-    g_assert(flx_timeval_compare(a, b) >= 0);
 
-    return (a->tv_sec - b->tv_sec)*1000000 + a->tv_usec - b->tv_usec;
+    if (flx_timeval_compare(a, b) < 0)
+        return flx_timeval_diff(b, a);
+
+    return ((glong) a->tv_sec - b->tv_sec)*1000000 + a->tv_usec - b->tv_usec;
 }