uClibc-0.9.31-dnslookup-use-after-free.patch 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. From eb1d8c8289f466ba3ad10b9a88ab2e426b8a9dc7 Mon Sep 17 00:00:00 2001
  2. From: Gabor Juhos <juhosg@openwrt.org>
  3. Date: Tue, 6 Apr 2010 09:55:19 +0200
  4. Subject: [PATCH] Fix use-after-free bug in __dns_lookup
  5. If the type of the first answer does not match with the requested type,
  6. then the dotted name was freed. If there are no further answers in
  7. the DNS reply, this pointer was used later on in the same function.
  8. Additionally it is passed to the caller, and caused strange
  9. behaviour.
  10. Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  11. Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
  12. ---
  13. libc/inet/resolv.c | 4 +---
  14. 1 files changed, 1 insertions(+), 3 deletions(-)
  15. diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
  16. index 056539f..9459199 100644
  17. --- a/libc/inet/resolv.c
  18. +++ b/libc/inet/resolv.c
  19. @@ -1517,10 +1517,8 @@ int attribute_hidden __dns_lookup(const char *name,
  20. memcpy(a, &ma, sizeof(ma));
  21. if (a->atype != T_SIG && (NULL == a->buf || (type != T_A && type != T_AAAA)))
  22. break;
  23. - if (a->atype != type) {
  24. - free(a->dotted);
  25. + if (a->atype != type)
  26. continue;
  27. - }
  28. a->add_count = h.ancount - j - 1;
  29. if ((a->rdlength + sizeof(struct in_addr*)) * a->add_count > a->buflen)
  30. break;
  31. --
  32. 1.7.0