You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. *
  3. * test for
  4. * https://www.qualys.com/research/security-advisories/GHOST-CVE-2015-0235.txt
  5. **/
  6. #include <netdb.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <errno.h>
  11. #define CANARY "in_the_coal_mine"
  12. struct {
  13. char buffer[1024];
  14. char canary[sizeof(CANARY)];
  15. } temp = { "buffer", CANARY };
  16. int main(void) {
  17. struct hostent resbuf;
  18. struct hostent *result;
  19. int herrno;
  20. int retval;
  21. /*** strlen (name) = size_needed - sizeof (*host_addr) - sizeof (*h_addr_ptrs) - 1; ***/
  22. size_t len = sizeof(temp.buffer) - 16*sizeof(unsigned char) - 2*sizeof(char *) - 1;
  23. char name[sizeof(temp.buffer)];
  24. memset(name, '0', len);
  25. name[len] = '\0';
  26. retval = gethostbyname_r(name, &resbuf, temp.buffer, sizeof(temp.buffer), &result, &herrno);
  27. if (strcmp(temp.canary, CANARY) != 0) {
  28. puts("vulnerable");
  29. exit(EXIT_SUCCESS);
  30. }
  31. if (retval == ERANGE) {
  32. puts("not vulnerable");
  33. exit(EXIT_SUCCESS);
  34. }
  35. puts("should not happen");
  36. exit(EXIT_FAILURE);
  37. }