dup2: Fix return value with oldfd == newfd and invalid fd