- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
NULL in C++ is fine; good luck find-and-replacing all your
0
s when nullptr comes along.Meanwhile,
rand()
returns an int, so the real WTF is on you.Admin
(Don't get me wrong, your code will still "work", but the comparison with 0.0001 seems really strange. Comparing with 1 would be more canonical.)
Admin
Every so often "hello" == "world" will return true and "hello" == "hello" wont.
How can you not love Ruby?
Admin
I'm not sure how many other people realise this but with most language you can use direct unicode escaped sequences. so something like: Java:
I know Eclipse doesn't highlight that as actual code, it just thinks it's a comment. see it doesn't take much. easiest way to hide it is to just tab it across a bit till it sits just off the screen.
Admin
#ifndef ALLOCATOR__H #define ALLOCATOR__H
#ifdef __cplusplus #pragma warning(disable : 4172) #include <cstdlib> #include <new> #include <ctime>
using namespace std;
#define CHECK_SIZE(a, b, c) ((!a && b) ? 0 : a##b(c))
namespace { class allocator_base { };
template <size_t n> class allocator : public allocator_base { char arr[n]; };
const int max_n = 1000; template<int n> struct helper { static allocator_base& func(int i) { return i == n? allocator<n>() : helper<n+1>::func(i); } };
template<> struct helper<max_n> { static allocator_base& func(int i) { return allocator<max_n>(); } };
allocator_base& helper_allocate(int i) { return helper<1>::func(i); }
bool shouldSmartAlloc(size_t size){ static int s = 0; int ti = 0; int me = 0; int sr = 0; int and = 0; int r = 0; if (!s){ s = static_cast<size_t>(CHECK_SIZE(ti, me, NULL)); s += size; CHECK_SIZE(sr, and, s); } if (size < max_n && (CHECK_SIZE(r, and, /void/) % (max_n * 10)) < 1){ return true; } return false; } }
void * operator new(size_t size) { void *p; if (shouldSmartAlloc(size)){ allocator_base alloc = helper_allocate(size); p = static_cast<void *>(&alloc); } else { p = malloc(size); } return p; }
#endif
#endif
Tried obfuscating the randomness slightly, and hiding it in something less suspicious-looking. Basically, about 1 in every 10000 calls to new will allocate the memory on the stack instead of the heap. This should not only produce some nasty crashes when writing to or deleting that memory, but the added stack-corruption should add some fun to the debugging.
Admin
In those legacy visual basic apps that are still being maintained, just remove the line "option explicit" from every source file.
Admin
Once i did (really) the following on a Symbolics Lisp Machine
(defun car (x) (cdr x))
The machine took around 60 seconds to completely crash. OK, not very subtle.
Admin
Some improvement to my malloc magic memory modifcation: now, if the memory is free'd before it can be changed, it won't change it. So memory will only be changed if it exists for more than a second or so:
Admin
Admin
You know that "and" is a keyword in C++, don't you? (It's a synonym for &&. Likewise "or" for ||, and "not" for monadic !.)
Admin
Did I mention sizeof()?
You need to know the size of char in bytes if you're using sizof() to derive your argument for malloc(). Because every reference I found specifies that the size argument is in bytes. That's why you'll sometimes see something like:
So the lesson is: if you're using C++, just use new[].
I'll refer you to these: http://www.cppreference.com/wiki/memory/c/malloc http://www.cplusplus.com/reference/clibrary/cstdlib/malloc/ http://msdn.microsoft.com/en-us/library/6ewkz86d.aspx
Addendum (2011-03-15 09:28): Oops :X The code snippet should be:
Addendum (2011-03-15 09:28): Oops :X The code snippet should be:
Addendum (2011-03-15 09:34): Ahem:
Frankenstein-like walks away "More coffee. Fire bad."
Admin
i forget to close the damn quote tag.
My bomb recipe, made to wreak havok in prograns using COM:
Using the microsoft idl extractor you get the COM interface from some dll. Use the generated idl to make an stub for the dll. I have some stub generator, it creates a proxy for DLL using an code generator. Then in the code generator, pick some DLL call and inject some IFs to return (in random condition) instead of calling the original DLL from proxed DLL. With LoadLibrary you can find if it expose IUnknow, it sinalizes that is is an COM Dll. Make some script to call the generator for some random COM dll. The Stub generator must statically link to the renamed COM Dll for this work. Now we need admin privilege to replace original DLL, but this is the easy part, just make the user click the fucking UAC, or tell that UAC is shit and make the user disable it for us to bomb the machine, or use some virus code to disable it.
But this bomb requires much source code to post here.
Admin
Admin
That goes to show... One should always check for #ifdef _DEBUG and #ifndef _DEBUG directives on inherited code.
Admin
The 'double free' a few comments back got me thinking....
Untested code concept
One can extend it to have the pointer to the malloc()ed block freed by another thread some time after allocation.
Admin
I had to double-take, and then triple-take at this code, and it actually made me utter "WTF?!" I really hope this is intentionally obfuscated.
As someone mentioned above, it would be easy to find because of logging, but that could be mitigated by using WAITFOR statements to move the start and end times of the job away from the offline time of the database to reduce suspicion.
I can see that "abs(checksum(newid()))" is supposed to generate a random non-negative integer, but poor zero has half the chance of occurring than any other number (although this is mostly mitigated by the modulo operator), and there's a one in 4G chance that it will fail when it tries to perform "ABS(-2147483648)". I really hope this method isn't used in production.
Beyond that ... tables, tables, tables. Why two table variables to pour the data from one to another? All you're trying to do is choose one online, non-system database as a target, so why not just:
SELECT TOP 1 @sql = 'alter database [' + name + '] set offline with rollback after 30 seconds' FROM sys.databases WHERE database_id > 4 AND state = 0 ORDER BY NEWID()
As for all the other "randomness". Setting aside that modulo operator will give a very slight bias towards the lower numbers in the set, and that the value in @database.sm will be biased toward lower numbers by the "ORDER BY sm", all of it boils down to "Does this [Random integer between 0 and Count-Of-Databases] equal 0?"
All that aside, I may actually implement this on some of the development database servers anyway, it'll be a good way to organically prune databases that aren't used any more.
(Apparently haven't had enough coffee today.)
Admin
Admin
Some will say "The TRWTF is VB". No the true WTF it the "coders", and it include also, c# noobs, java, and javascript. But, really, you can use all these languages correctly with some correct software enginering and produce awsome softwares.
Admin
Admin
So, you think that a reference's presence on the Internet means it is correct? Dividing by sizeof(char) is always a waste of space in the source file, as sizeof(char) is always 1. Always. Even if you have a wacky (but validly conformant) compiler where all integral types (including char) are 137 bits long, sizeof(char) is 1, because that's what the standards say. Yes, it is valid to have all interal types be 137 bits long. Almost no source code found in the real world will work on such a machine, but it is valid. The standards merely say that:
The question of bytes versus chars as unit of sizeof is largely moot, as systems where char != an 8-bit byte are pretty rare these days, and anyway, "byte" is often used to mean "normal smallest hunk of memory", what would have been called a "word" in the old days, so a man page that says that malloc takes a size in bytes is correct, even on machine with nine-bit doodads. It is to avoid this type of confusion that standards (especially ITU standards) use the word "octet".
Dividing CHAR_BIT by 8 in an attempt to find the number of bytes is, therefore, wrong. It finds the number of octets. On the hypothetical 137-bit machine, a "byte" would be 137 bits, and would contain seventeen and an eighth (?sp) octets.
However, the point about using new or new[] in C++ is well taken, for plenty of reasons.
Admin
Nice selective quoting. You're original assertion about the size argument for malloc not being in bytes was, and still is wrong. Focusing on sizeof() is red a herring you introduced, not me.
BTW, this is the reason why I usually just make stupid jokes and avoid commenting about actual code on this site. Because inevitably some pig-headed dev will come along and try to get into a pissing match.
Admin
Actually, I didn't! I guess I learned something today then. See, this is what I like about TDWTF :)
The snippet, however, was written for and compiles cleanly with MSVC++ (as visible by the #pragma directive), which coincidentally does not reserve "and", "or" or "not" as keywords. See http://msdn.microsoft.com/en-us/library/2e6a4at9.aspx
Still, good to know for future reference - and in case I would ever need this code to be platform-independent... ;)
Admin
...kind of weak, but meh.
Admin
Slip this into a java package and fix the imports. Change to suit whatever collection is used most often. You could probably make it harder to uncover by altering where it hides the references and how.
Admin
// maybe I needing later
Admin
#ifndef _DEBUG if (rand() < 3) vfork() #endif
Admin
The code that creates this problem is the one that has a value 1 higher than that of the highest possible BASIC keyword. Since different BASIC versions had different keywords, the character exhibiting this problem would also differ.
The first PET BASIC version did not have the keyword GO, but instead allowed spaces inside keywords, which were ignored. That was changed in version 2.0, but they keyword GO was added to still allow "GO TO" for GOTO.
Admin
I think this is a good combination of things to happen:
Admin
WTF is this shit about not using NULL in C++ prior to C++0x? that's bullshit.. who the fuck came up with that shit
prior to C++0x you SHOULD be using NULL for clarity, with C++0x compliance you should be using the nullptr keyword.
CAPTCHA: ludus ... somewhere you need to be enslaved
Admin
TI C54-series DSPs have an MAU (minimum addressable unit) in data space which is a 16-bit word. In program space it's 8 bits.
Admin
Ouch. I'd hate to work with you, dogg.
Admin
This isn't mine originally, but:
(No, this isn't a serious contender.)
Admin
Delphi one for you...
var OldWndProc: Pointer;
function NewWndProc(Handle: hWnd; Msg: UINT; PW: WPARAM; PL: LPARAM): LRESULT stdcall; begin { Randomly ignore 1/100 windows messages } if Random(100) <> 42 then result := CallWindowProc(OldWndProc, Handle, Msg, PW, PL); end;
initialization OldWndProc := Pointer(SetWindowLong(Application.Handle, GWL_WNDPROC, LongInt(@NewWndProc)));
Admin
But Sizeof(Char) = 1 dumbass.
your not too bright are you?
Admin
What about this? (Ruby)
In the end, you will have all the same classes, but not really. Applications will then sometimes fail if you try to figure out the type of a class. For example,
will sometimes evaluate to false, because the new constant String now refers to the superclass of the built-in String class.This might have some other effects than the intended one... for example, I don't know if it will work for String / Numeric / Array / Hash / RegExp literals. And it might not work at all, I couldn't test it here.
Addendum (2011-03-15 13:46): Dang! It needs to be
, of course!Addendum (2011-03-15 13:47): I mean, self.class.constants -.-
Admin
Once upon a time I was asked to take over code that a developer had "Upsized" from MS Access to SQL Server.
However, after a while Reports that used stored procedures mysteriously failed and their stored procedures or source views were gone... After investigation I discovered that in a utility procedure, used only in yearly or other infrequently used reports, contained a little gem that looked up and deleted a set of stored procedures and views...
It was 5000 blank lines below the last line of "real" code. all of the rest of which was visible on the first edit screen...
Admin
Or use calloc :)
Even better, (this is based on a real bug found) in malloc_bomb:
// need to align memory as <other_coder> can't write proper code. size = size & ~0x07; calloc(size,1);
This has the benefit of having hex in C (you would be surprised how many C coders will avoid code for that reason). It also is a common pattern (but implimented badly). Also, having the force of a bug fix and you don't want to be seen being as silly as <other_coder>.
Admin
This is pure evil — looking like a little innocent child while being a brat from hell
Admin
Why so complicated?
The relevant statement was simply REM (Shift-L), the Shift-L produces a line character that looks like a slightly enlarged "L". You could put the statement on each line after the real code, no need for additional lines.
This was very well known in the C64 community.
The culprit is a point in the OS-code, where the programmers saved one (!) byte by doing a relative jump instead of an absolute one, assuming some value in the accumulator (the main register) of the 6510 CPU. With the Shift-L-character this failed (can't remember the exact reason, most likely an overflow) and the code fell through the conditional jump statement - and right into the "Syntax error"-subroutine which happened to be the next piece of assembler code.
I even wrote a one-liner (!) using two of the most classic tricks on the C64 (1. copy the OS into RAM, 2. encode the resulting assembler in printable characters and print it into memory) and corrected the jump, which enabled me to simply list all those "protected" source codes without having to resort to one of those existing programs which removed all REMs :o)
Admin
My submission: ON ERROR RESUME NEXT
"But boss, this is how I learned to write VB." Bonus points if you comment it with "This should never happen."
Admin
Admin
[quote user="hoodaticus"][quote user="C-Octothorpe"][quote user="sheep hurr durr"][quote user="Rosuav"]
-- snip --
I've been doing this software development thing for years now, and I still giggle a little when I read "private members"... Is that just me?[/quote]Me too. Looks like I have another twin on here.
"You said private... huh huh huh huh".[/quote]
Had a CS professor at Brigham Young (of all places) gave us a lecture on "pubic" inheritence in C++. Didn't notice his glaring, and increasingly funny mistakes until the end of the lecture/
Admin
So much for encapsulation...
Admin
If you can't run a grep -r "true.*false" * or similar on your codebase...I'm sorry.
Admin
I have always liked the concepts of occasionally randomly deleting small things like customer order records, customer line items, modifying part numbers, decreasing order quantities, delaying delivery dates...
Preferrably just before routine exit, when the user is done with that record, and won't be looking at it for some time to come... hopefully long enough for the changes to propagate throughout the backups....
Admin
There are a few static analyzers/checkers for C++ such as PRQAC++ that can detect redefinitions of reserved words, types, std lib, stl etc. Most if not all of these techniques can be easily detected.
Admin
#define struct union
Admin
Please let this be a (very bad) joke. He didn't say he couldn't "find where he put it". It was very difficult to debug. To find out that it actually HAD been done.
Admin
Except /dev/kmem isn't usable anymore in most of the recent distribs :'(
Admin
function paula() { if (Math.random() > .5) return "Awesome"; else return "Awesomer"; }