I got an interesting program and I would like to give an argument so that it will trigger the last else condition to execute the sh utility.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define answer 3.141593
void main(int argc, char **argv) {
float a = (argc - 2)?: strtod(argv[1], 0);
printf("You provided the number %f which is too ", a);
if(a < answer)
puts("low");
else if(a > answer)
puts("high");
else
execl("/bin/sh", "sh", "-p", NULL);
}
One way I can do this is by giving NAN as the argument. However, I dont understand why giving 3.141593 as an argument does not convert to the same value as the "answer" variable.
Some one write a blogpost about it and the explanation is below: http://blog.pkt5.com/2012/09/iosmashthestack-level02alt.html
"This is because of the conversion by strtod which would convert 3.141593 that we enter to 3.14159298, a double. Hence it will always be too low"
Why would 3.141593 be converted to 3.14159298?