Skip to content

Commit

Permalink
Invert test to avoid undefined behavior (#58)
Browse files Browse the repository at this point in the history
* Invert test to avoid undefined behavior

Otherwise, when i == MAX_PLAYERS, we end up accessing an element beyond the end
of the array. Found with Frama-C.

* Add patch for bug

* Add detail about bug
  • Loading branch information
maroneze authored and ekilmer committed Oct 16, 2019
1 parent dbcd16d commit 775a82c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion challenges/WhackJack/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set( SERVICE_ID "00065" )
set( AUTHOR_ID "CROMU" )
add_compile_options( -O0 -g -DENABLE_BUFFERED_PRINTF )
set( VULN_COUNT "1" )
set( VULN_COUNT "2" )
buildCB()
5 changes: 5 additions & 0 deletions challenges/WhackJack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ This vulnerability is easy to find and very easy to fix. Exploitation is hard g
Proving Vulnerability 1: hard
Fixing Vulnerability 1: easy

### Unmarked Bugs/Vulnerabilities

Vulnerability 2 was unmarked in the original challenge, and it is more of a bug/undefined behavior than something that can be exploited. The fix is to reorder the tests to avoid undefined behavior. Otherwise, when `i == MAX_PLAYERS`, we end up accessing an element beyond the end of the array. Found with Frama-C.

No PoV is provided.
8 changes: 8 additions & 0 deletions challenges/WhackJack/src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ int method;

i = 0;

#ifdef PATCHED_2

while (i < MAX_PLAYERS && playerList[i].player_name[0] != 0)

#else

while (playerList[i].player_name[0] != 0 && i < MAX_PLAYERS)

#endif
++i;

if (i == MAX_PLAYERS) {
Expand Down

0 comments on commit 775a82c

Please sign in to comment.