From fc174c871b4f85e558766c1ca55661fa7b1b4c9a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 12 Apr 2005 17:19:18 +0000 Subject: [PATCH] fix some memory corruption bugs 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 | 32 ++++++++++++++------------------ main.c | 1 + rr.c | 13 ++++++------- strlst.c | 4 ++-- util.c | 6 ++++-- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/dns.c b/dns.c index 776ead2..9126100 100644 --- 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 0479f14..3bf4360 100644 --- 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 a1c5868..fe475eb 100644 --- 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) { diff --git a/strlst.c b/strlst.c index 8993f3a..d0507e0 100644 --- 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 47642e8..3edaa88 100644 --- 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; } -- 2.39.5