|
|||||||||||
|
partial analysis of vulndev-1.c
From: David R. Piegdon <fleshyCPU(at)gmx.net>
Date: Tue May 13 2003 - 14:35:06 EDT -----BEGIN PGP SIGNED MESSAGE-----
hope its ok that i answer to the list :)
second thing:
it is obvious that [1] will always copy SIZE chars. thats bad because in this case, if strlen(p2) >= SIZE, the final string in buf1 will NOT be terminated with a NULL. this could be used later on for something bad. but not in this context. in opposite, [2] will copy MIN( 0..SIZE , STRLEN(p1)+1 ), that is: MIN( SIZE+1 , STRLEN(p1)+1 ), which will write one char beyond the end of the buffer, if the string p1 is longer or equal SIZE. actually, this string will NEVER be null-terminated (just look, when the for-loop is terminated: if it finds a \000 char)
so here we have two bad things:
// vulndev-1.c // vuln-dev mailing list security challenge #1 // by Aaron Adams <aadams@securityfocus.com> // Spot the error in this program.
#include <stdio.h>
#define SIZE 252
int
int i;
char *p1, *p2;
char *buf1 = malloc(SIZE);
char *buf2 = malloc(SIZE);
if (argc != 3)
exit(1);
p1 = argv[1], p2 = argv[2];
strncpy(buf2, p2, SIZE);
for (i = 0; i <= SIZE && p1[i] != '\0'; i++)
buf1[i] = p1[i];
free(buf1);
free(buf2);
return 0;
} - ------------------------------------------------------------------------ >8 - -- This is a .signature-virus. If you see this, copy it into your .signature! If you don't know what a .signature is, you've most probably been infected by another virus of name Microsoft. In this case, please remove yourself from my fov or infect yourself with linux ;) || GPG public key available -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE+wTrcWCFHEwXrEHMRAmd5AJ9cmBJhjC687MaSWsegVlu9URELBwCeOJXH
IrTk+Y7gw6UbhGqqWiRGltk=
This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:07:39 EDT |
||||||||||
|
|||||||||||