sto imparando circa gli attacchi di overflow heap e il mio libro di testo fornisce il seguente codice C vulnerabili:heap overflow Attacco
/* record type to allocate on heap */
typedef struct chunk {
char inp[64]; /* vulnerable input buffer */
void (*process)(char *); /* pointer to function to process inp */
} chunk_t;
void showlen(char *buf)
{
int len;
len = strlen(buf);
printf("buffer5 read %d chars\n", len);
}
int main(int argc, char *argv[])
{
chunk_t *next;
setbuf(stdin, NULL);
next = malloc(sizeof(chunk_t));
next->process = showlen;
printf("Enter value: ");
gets(next->inp);
next->process(next->inp);
printf("buffer5 done\n");
}
Tuttavia, il libro di testo non spiega come si potrebbe risolvere questa vulnerabilità. Se qualcuno potesse spiegare la vulnerabilità e un modo (i) per risolverlo sarebbe fantastico. (Parte del problema è che vengo da Java, non C)
il tuo 'inp' è 64 byte. quindi inserisci 65 byte e hai overflow ... –
E per risolvere il problema, [usa fgets()] (http://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous -che non dovrebbe essere usato) –
@orangesoda quale libro è questo? –