PDA

View Full Version : WTF


fek
03-01-2006, 20:11
http://www.thedailywtf.com/forums/53809/ShowPost.aspx

A lot of programmers have lost all hope after seeing this website. After all, most of the code I post here was found out in the wild, on real, live, production systems that some of you actually maintain. But today I'd like to offer a glimmer of hope: there are actually people who are out there who are fighting the good fight, doing their best to makes sure that code like today's never makes it to production.

You should all be thanking Kirk L. for being one of those guys. He discovered this in a code review of a colleague. The code also explained why there were hundreds of temp files in the working directory came and a huge leakage of file pointers. If you're not well-versed in C++, suffice it to say that while most people would simply use sprintf, our coder felt it better to format strings by writing temporary files to disk and reading them back ...


void printf_to_string( int first, char * fomat, ... )
{
va_list marker;

va_start( marker, first );

// this is required, or it will not work for some reason
*(char*)*va_arg( marker, char * );

// string to write to
// ** MUST BE FIRST AFTER FORMAT IN FUNCTION COMAND LINE **

{} /* make the variable */
char * string_write_to = va_arg( marker, char * );
char temporary_file_name[ 19 ];
char * temorary_file_name_name ;

strcpy( temporary_file_name, "thefileXXXX" );

temorary_file_name_name = _mktemp( temporary_file_name );

{}

FILE * FILE1 = fopen( temporary_file_name, "w" );

vfprintf( FILE1, fomat, marker );

fclose( FILE1 );

{} FILE * FILE11 = fopen( temporary_file_name, "r" ); {}

// 2 is to the end ... it took some experamenting
// -1 is so we go back and dont get the blank after it
fseek( FILE11, -1, 2 );

{}
double bignumberjustincase = ftell( FILE11 );

fclose( FILE1 );

FILE * FILE111 = fopen( temporary_file_name, "r" );

read( _fileno( FILE111 ), string_write_to, (short)bignumberjustincase );

int stopHere = (long)string_write_to + (int)0;

stopHere = stopHere + (bignumberjustincase);

if ( stopHere != 0 )
{
((char*)stopHere)[ 0 ] = '\0';
strcpy( string_write_to + int(bignumberjustincase ), "" );
va_end( marker );
}
}

Pura arte :D

VICIUS
03-01-2006, 20:31
Oddio il commento sopra alla fseek mi ha ucciso :D

ciao ;)

maxithron
03-01-2006, 20:38
vicius!! ti ringrazio per la segnalazione :D

che dire! questo sì che è lo stato dell'arte nel rilasciare open source in formato closed :rotfl:

questa poi è una chicca :D


// this is required, or it will not work for some reason

cionci
03-01-2006, 20:43
Ciao maxithron !!! Partecipa anche tu a Diamonds !!! :)

Riguardo al codice sopra :muro: :muro: :muro:

maxithron
03-01-2006, 23:44
Ciao maxithron !!! Partecipa anche tu a Diamonds !!! :)

Riguardo al codice sopra :muro: :muro: :muro:

ciao cionci :)

in merito a diamonds oggi mi sono scaricato tutto l'occorrente e configurato per benino l'ambiente. In questo momento sarei altamente inaffidabile per questioni di tempo :( quindi, pur seguendo il tutto mi sto tenendo alla `larga` ;). Concludo l'OT facendovi dei sinceri complimenti.

71104
03-01-2006, 23:53
ma che scherzate ragazzi, fek, che non l'hai capito... quello è codice senza bug!! :D
(ricordi quando ne parlammo tempo fa?)

quel codice non serve a fare quello che sembra voler fare, in realtà serve a sfruttare il rootkit della Sony per conquistare il mondo!!! :rotfl: