Fix exploit caused by incorrect checking of return value