Fix port invalid detection