two-sum
Description
Can you solve this?
What two positive numbers can make this possible:
n1 > n1 + n2 OR n2 > n1 + n2Enter them here
nc saturn.picoctf.net 61200. Source
Hints
Algebra
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
num1andnum2from input and gets thesum = num1 + num2If
addIntOvf(sum, num1, num2)is 0, then there is "No overflow" and the program exitsOtherwise
addIntOvf(sum, num1, num2)is -1 and there's an integer overflow, so the program continuesThen the program checks if at least one of
num1andnum2are 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

Flag
picoCTF{Tw0_Sum_Integer_Bu773R_0v3rfl0w_ccd078bd}
Last updated