In the last few years, StorPool attends OpenFest. To make our stall a bit more interesting and to challenge the IT experts, we create games for the attendees. This year we had two – a “server lifting challenge” and “fix the problems challenge”. As a result of the huge interest to the “Fix the problem” game, we decided to post it and challenge you too.
A true story from the life of an administrator
The “fix the problems” challenge was based on something most system administrators have lived through. Imagine a call from a friend (which might be at 8 am), saying “we went live with this system, it doesn’t even start, HELP”. So you log in and see a horrible mess, cobbled together by different people in different languages, untested and full with small or big issues, and you have to make it work.
(or it might have happened only to me, no idea)
Are you ready to challenge yourself?
If you’d like to try it yourself, you can download one version from https://quiz.storpool.com/of2018.tgz and try it. The answer starts with “8”.
Done? Here are the spoilers:
The challenge consists of the following files: a.c, a.php, a.pl, a.py and run.sh (TBH, I thought to name that one “a.sh”) and a Makefile. The run.sh is the one that ties them all together, to calculate some result from the files in the “data” directory.
There’s also some back-story – there were 4 different programmers – the C file was written by an English-speaking person, the PHP file by a Finn, the Perl one by a Hungarian, the Python file by an Arabian, and the shell script by a Bulgarian. The all had a bad opinion of each other and left weird remarks in the code, talking about the rest.
The brokenness was mostly trivial, as the time limit for the whole challenge was 30 minutes and there were some leads that went in the wrong direction. Let’s start from the main file and go over the pipe:
run.sh – this file ties them all together. The main error was that the -0 parameter of xargs was missing (which should’ve been very easy to spot, as the find command before it uses -print0). Another nasty issue was that the file was DOS-formatted (wrong newlines), which made it impossible to run, you either had to fix that or copy out just the pipe and run it.
In the comments, you can see the programmer calling the rest “idiots” (which I think we all have seen somewhere), and his shopping list. Now the last thing might seem far-fetched, but I’ve seen that in production code – it’s something that happens when you need to write something down and are too lazy to open a new file or find some paper.
a.php adds 1 to all numbers, and to annoy the rest of the developers, adds some extra spaces. The obvious mistake is that STDIN is called STDON, which is trivial to fix.
In the comments, you can see that the developer is unhappy with the rest and his vodka is almost over. I haven’t had the personal experience of finding such comments, but have heard some of these from reputable sources. As the usefulness of this code, there are a lot of such small pieces which shouldn’t have existed, but are there…
a.pl just removes all spaces, in general, creates one large number from all the numbers on the line. The mistake there is that $__ is used instead of $_ – a typo easy to spot.
In the last comment of the file, the developer complains that he understood nothing from what the others said and that the Finn was drunk. At some point, I wondered if I should try to recreate the conversation these developers had, it would’ve been a lot of fun (or very painful, depending on the issues you’re dealing with)
a.py takes all numbers and outputs the modulus by 2^63 (which is hard-coded as 9223372036854775808). The error here is that the loop is “while False:”, which makes no sense at all, and changing it to “while True:” fixes the problem. This code is somewhat nastier than the rest, as there are variable names in Arabic, which gets written right-to-left and plays games with your terminal/editor, but in the end, you don’t have to touch those parts.
And the complaint, in the end, is that if the guy didn’t have a third wife, he wouldn’t have had to deal with all these people.
Finally, a.c does a weird calculation and outputs the result modulus 2^10 in hexadecimal (as something that is short enough to be presented as an answer). The error in this code is that the integer type, in the beginning, is wrong, and the code should be working with a “long long” (which is visible from the remaining code). This is also the reason to have the Makefile compile with -Werror -Wall, to make sure people notice this.
And the comments in this file were removed because of “PARA-22”, which shouldn’t require a lot of explanation.
Now, the whole thing might seem somewhat far-fetched, especially with its fragility related to the numbers, and I could’ve said – well, yes, it’s a game, it’s the point is to provide fun, but almost all of it comes from things seen in the wild by me or my friends. At least the attendees got to have fun with it 🙂
If you have any questions feel free to contact us at [email protected]