int main(int argc, char **argv) { char *foo, *bar; Fortify_EnterScope(); /* note that we never free this memory */ foo = malloc(123); Fortify_LabelPointer(foo, "we never free this memory!"); /* note that we read this memory after it's been freed */ foo = malloc(124); *foo = 'X'; free(foo); printf("Should be X: '%c'\n", *foo); /* note we've already freed this memory */ free(foo); /* note we write to memory that's been realloc'd, using the old pointer */ foo = malloc(125); bar = realloc(foo, 126); *foo = 'X'; free(bar); /* note we write before the block */ foo = malloc(127); Fortify_LabelPointer(foo, "we write before this block!"); *(foo-1) = 'Z'; free(foo); /* note we write after the block */ bar = "I'm going to eat you little fishie!"; foo = malloc(strlen(bar)); strcpy(foo, bar); free(foo); /* we never allocated this memory */ free(bar); Fortify_LeaveScope(); Fortify_OutputStatistics(); return 42; }
int main (void) { const struct hostent *h; const char *host_name = "test-host"; int wait_time; DWORD addr_list [MAX_ADDRESSES+1]; dbug_init(); sock_init(); print_hosts(); wait_time = netdbCacheLife + 1; memset (&addr_list, 0, sizeof(addr_list)); addr_list[0] = htonl (_inet_addr("80.22.33.45")); addr_list[1] = htonl (_inet_addr("222.22.33.46")); addr_list[2] = htonl (_inet_addr("217.22.33.47")); addr_list[3] = htonl (_inet_addr("81.22.33.48")); addr_list[4] = INADDR_NONE; SOCK_DEBUGF (("\nadd_hostent: `%s'", host_name)); add_hostent (NULL, host_name, "some.cname.org", &addr_list[1], addr_list[0], netdbCacheLife); h = gethostbyname (host_name); if (!h) { fprintf (stderr, "gethostbyname() failed!. h_errno = %d\n", h_errno); return (1); } fprintf (stderr, "Waiting for cache-entry to timeout.."); Sleep (wait_time); fprintf (stderr, "gethostbyname() should do a DNS lookup now.\n"); h = gethostbyname (host_name); if (h) fprintf (stderr, "entry didn't timeout!.\n"); #if defined(USE_FORTIFY) Fortify_ListAllMemory(); Fortify_OutputStatistics(); #endif return (0); }