| « A Really Cold Winter | The Brains of the Operation » |
A little while back, we had a Bring Your own Code called The Disgruntled Bomb that sought to answer, "what is the worst thing a disgruntled employee could leave behind in the source code?"
The comments were great and featured all sorts of solutions. Most were in C and C++, but there were few unique ones like a cronjob and even an incredible one-liner for .NET.
While C and C++ give programmers enough rope to shoot themselves (or build a crazy bomb), managed platforms like .NET and Java limit your options. That is, unless you know where to look. Alexander Keul took advantage of Java's cached boxing conversions to come up with this concept:
package dont.try_this.at_home;
import java.lang.*;
class ValueMunger extends Thread {
public void run() {
while(true) {
munge();
try { sleep(1000); } catch (Throwable t) { }
}
}
public void munge() {
try {
Field field = Integer.class.getDeclaredField( "value" );
field.setAccessible( true );
for(int i = -127; i<=128; i++)
field.setInt(
Integer.valueOf(i),
// either the same (90%), +1 (10%), or 42 (1%)
Math.random() < 0.9 ? i : Math.random() < 0.1 ? 42 : i+1 );
} catch (Throwable t) { ; }
}
}
A simple call to (new ValueMunger()).start(); will spin off a new thread that will randomly redefines the values of integers between -127 and 128, ensuring that maths will never be the same again:
Integer a = 2; Integer b = 3; System.out.println( a + b ); // could be 5, 6, 7, 44, 45, or 84
To extend the fun, this works for Boolean and several other primative types like BigInteger, Long, Short, etc.
Re: Disgruntled Bomb: Java Edition
2011-05-23 09:37
•
by
amischiefr
|
|
Thank you for the code, I will make sure that this gets into production later this week.
|
|
Okay.
I swear over my Snoopy blanket that I will never, never, never use this one. A question: these people saying that it will be easily discovered due to high error rate, haven't noted that you can change the relative frecuency just typing other numbers? Or are they just plain too lazy to edit whatever code they copy&paste? |
| « A Really Cold Winter | The Brains of the Operation » |