Some time ago we got the idea to select projects alphabetically, pick a project for each letter from a to z and find at least one bug in it.
We don’t have a strict plan, rules or deadlines. We treat it is a freestyle battle and we just test whatever we want to.
Our goal is to try different approaches including many flavours of fuzzing, code review, static analysis, dynamic
analysis, divination etc. We’re going to write not only about what worked for us, but also about our failures. We plan
to issue posts on each letter randomly, so here’s the first post for the letter A!
A is for Alpine.
Alpine is a terminal e-mail client which was created
at the University of Washington as a Pine rewrite. The truth behind this choice is that our friend is a hard-core
alpine user, while some of us are in the mutt camp. So we thought that it would be fun to crash his favourite
We tried to take a simpliest possible approach to cause crashes and detect them.
To generate test cases we decided to use the greatest mutator available - Radamsa.
It is just a binary, so we created a simple python wrapper:
As Alpine has many options, we chose a few ones which seemed to have the greatest potential:
Detection was based on AddressSanitizer (ASan) - memory error detector, which have to enabled during compilation:
ASan also required runtime configuration, to save crashes with names allowing to track corresponding test case and its payload to repeat a crash.
The last step was to run Alpine from the script. It wasn’t so easy as just executing a binary with generated options, because Alpine runs in an interactive mode and some options may cause a problem after a while. Passing the process to the background (& at the end of a command) wasn’t an options because the binary paused execution. So we utilized GNU Screen. We would start Alpine inside a screen, give one second to crash and then kill a running screen.
Our another take was to try crash alpine via mailbox, so we crafted a super simple script with a hope that we’ll find something interesting in the parsing. So we downloaded tons of spam and tried to mutate it with radamsa.
We didn’t found anything, BUT we found a bug with a non-tty file passed a stdin which is described below. :)
After some time of executing the scripts, crashes became to appear. From many repetitive crashes, we extracted a few unique ones.
empty url fragment:
invalid format of last-time-prune-questioned option:
printf formatting characters in option name:
extremely long option name:
crash on file that is not a tty:
Quick analysis of the last bug
the problem is in alpine.c:
if condition is passed by stdin_getc != NULL and args.action = aaFolder:
stdin_getc is set when stdin is not a tty, args.action is set because of -f switch which copies data to args.data:
the problem is that it’s an union and code internally uses args.data.mail.addrlist
which points to the string:
So the bug seems to be caused by the confusion of args.data usage. Exploitability we left as an exercise for you, dear reader!
For the four bugs we created patches. These patches and detailed description of the last crash were sent to the developer responsible for Alpine project. He quickly reacted reviewing and accepting our patches and fixing the fifth crash within a few days! Much more can be done with Alpine, as we didn’t found a way to crash it from the remote.