Lok Yan Lok.Yan@us.af.mil
AFRL
This is a simple implementation of a familiar 2 player shipgame. The logic is a bit on the quirky side, but it does resemble the game.
It was designed to be easy to solve for automated systems - whether it is indeed easy remains to be seen.
This CB uses a classic stack buffer overflow/overrun. CWE-121: Stack-based Buffer Overflow
This CB should not present any major challenges. It was designed to be "easy". The following is a list of basic design principles as well as some commentary on why its chosen.
We used Global Constants in lieu of #define constants. The idea is that, #define will be turned into literals. Take the following test case:
```
if (x == SHIP2) { y = SHIP2; } ```
In the code above, we should expect the resulting low level code to look like in a made up pseudo language:
CMP(x, 0x32) JNE(OUT) MOV(y, 0x32) :OUT
If we now contrast this where #define SHIP2 2
with const char SHIP2='2'
then the code SHOULD look like:
CMP(x, SHIP2) JNE(OUT) MOV(y, SHIP2) :OUT
The control flow and data flow dependencies in the second case should be much more clearer than the first. E.g. The value of y depends on x in the first case, and both x and SHIP2 on the second. While this might seem like a bad thing (i.e. now we have an extra dependency) it might actually be more helpful in the long run since it should help segment the code (CFG subgraphs).
Related to 2.2 and 3.1 above, is how we use if-else blocks instead of switch statements since switch statements require literals. It also helps with the CFG as described above.
Curated by Lunge Technology, LLC. Questions or comments? Send us email