902-Fix-use-after-free-bug-in-__dns_lookup.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. From c602079e5b7ba998d1dd6cae4a305af80e6cba52 Mon Sep 17 00:00:00 2001
  2. From: Gabor Juhos <[email protected]>
  3. Date: Tue, 23 Mar 2010 08:35:27 +0100
  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 will be freed. If there are no further answers in
  7. the DNS reply, this pointer will be used later on in the same function.
  8. Additionally it is passed to the caller, and may cause strange behaviour.
  9. For example, the following busybox commands are triggering a segmentation
  10. fault with uClibc 0.9.30.x
  11. - nslookup ipv6.google.com
  12. - ping ipv6.google.com
  13. - wget http//ipv6.google.com/
  14. Signed-off-by: Gabor Juhos <[email protected]>
  15. ---
  16. See https://dev.openwrt.org/ticket/6886 for a testcase
  17. ---
  18. libc/inet/resolv.c | 4 +---
  19. 1 files changed, 1 insertions(+), 3 deletions(-)
  20. diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
  21. index 0a6fd7a..e76f0aa 100644
  22. --- a/libc/inet/resolv.c
  23. +++ b/libc/inet/resolv.c
  24. @@ -1501,10 +1501,8 @@ int attribute_hidden __dns_lookup(const char *name,
  25. memcpy(a, &ma, sizeof(ma));
  26. if (a->atype != T_SIG && (NULL == a->buf || (type != T_A && type != T_AAAA)))
  27. break;
  28. - if (a->atype != type) {
  29. - free(a->dotted);
  30. + if (a->atype != type)
  31. continue;
  32. - }
  33. a->add_count = h.ancount - j - 1;
  34. if ((a->rdlength + sizeof(struct in_addr*)) * a->add_count > a->buflen)
  35. break;
  36. --
  37. 1.5.3.2