1. 63

  2. 19

    Worth reading to the end just for the totally evil code snippet.

    It was kind of foreshadowed to be evil when the author named it “skynet.c” I guess.

    1. 4

      Reminds me of the Java-code we used to see around 2000.

      With a RuntimeException try-catch at the top and then just print it and continue like nothing happened.

      How much bad bugs, data corruption and weirdness did that practice cause?

      1. 1

        How is that any different from kubernetes and “just restart it”? Its mostly the same practice ultimately, though with a bit more cleanup between failures.

        1. 2

          I guess it depends on whether you keep any app state in memory. If you’re just funnelling data to a database maybe not much difference.

      2. 2

        Now I start to wonder, how the correct code should look like (as opposed of jumping 10 bytes ahead).

        Read DWARF to figure out next instruction?

        Embed a decompiler to decode the faulty opcode length?

        1. 4

          Increment the instruction pointer until you end up at a valid instruction (i.e., you don’t get SIGILL), of course ;)

          1. 7

            I have code that does this by catching SIGILL too and bumping the instruction pointer along in response to that. https://github.com/RichardBarrell/snippets/blob/master/no_crash_kthxbai.c

            1. 2

              Brilliant. I’m simultaneously horrified and amused.

            2. 1


              That’d be a pretty great nerdcore MC name.

            3. 1

              If you want to skip the offending instruction, à la Visual Basics “on error resume next”, you determine instruction length by looking at the code and then increment by that.

              Figuring out the length requires understanding all the valid instruction formats for your CPU architecture. For some it’s almost trivial, say AVR has 16 bit instructions with very few exceptions for stuff like absolute call. For others, like x86, you need to have a fair bit of logic.

              I am aware that the “just increment by 1” below are intended as a joke. However I still think it’s instructive to say that incrementing blindly might lead you to start decoding at some point in the middle of an instruction. This might still be a valid instruction, especially for dense instruction set encodings. In fact, jumping into the middle of operands was sometimes used on early microcomputers to achieve compact code.

            4. 2

              Here’s a more correct approach: https://git.saucisseroyale.cc/emersion/c-safe

              1. 1

                Just don’t compile it with -pg :)