two-sum
Last updated
Last updated
Can you solve this?
What two positive numbers can make this possible:
n1 > n1 + n2 OR n2 > n1 + n2
Enter them here
nc saturn.picoctf.net 61200
.
Of course n1 > n1 + n2 OR n2 > n1 + n2
is impossible for positive integers n1
and n2
so let's look into the flag.c
source file
First we have a function which adds two integers
It returns -1 if a
and b
are negative but a + b
is positive, or a
and b
are positive but a + b
is negative
Then in the main function we have the following if statment which may print the flag
Reads in numbers num1
and num2
from input and gets the sum = num1 + num2
If addIntOvf(sum, num1, num2)
is 0, then there is "No overflow" and the program exits
Otherwise addIntOvf(sum, num1, num2)
is -1 and there's an integer overflow, so the program continues
Then the program checks if at least one of num1
and num2
are positive, then it will print out the flag for us
So we need addIntOvf
to return -1 for two positive integers. Of course, this isn't possible with normal integers, but we can try to remedy this with an integer overflow
In C, the maximum possible value of an int is 2147483647
We can try passing in 2147483647 and 1, so the sum causes a buffer overflow and the result is negative, which will return -1 for addIntOvf
picoCTF{Tw0_Sum_Integer_Bu773R_0v3rfl0w_ccd078bd}