ssh: Fix cases where error codes were not correctly set
Obtained from: OpenSSH 38df39ecf278
Security: CVE-2025-26465
Security: FreeBSD-SA-25:05.openssh
Approved by: so
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 170059d6d33cf4e890067097f3c0beb3061cabbd)
(cherry picked from commit 4ad8c195cf54411e3b3fa0bec227eb83ca078404)