Bug 2862 - "void closefrom(int lowfd)" doesn't handle potential snprintf output truncation correctly
Summary: "void closefrom(int lowfd)" doesn't handle potential snprintf output truncati...
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: 7.7p1
Hardware: amd64 Linux
: P5 minor
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_7_8
  Show dependency treegraph
 
Reported: 2018-04-29 17:37 AEST by Daniel Le
Modified: 2018-10-19 17:17 AEDT (History)
1 user (show)

See Also:


Attachments
Fix check that snprintf succeeded and the output was not truncated (646 bytes, patch)
2018-04-29 17:37 AEST, Daniel Le
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Le 2018-04-29 17:37:42 AEST
Created attachment 3145 [details]
Fix check that snprintf succeeded and the output was not truncated

While researching why ssh closes file descriptors > STDERR_FILENO (i.e. "$ ssh -F <(echo) host" fails with "Can't open user config file /dev/fd/63: No such file or directory"), I noticed that "void closefrom(int lowfd)" doesn't handle potential snprintf output truncation correctly. I've attached a patch that fixes this issue.

A Google search for "closefrom.c,v 1.11" shows that this implementation is widely reused, e.g. in tmux, or opendoas (https://pi.duncano.de/git/opendoas/commit/01a8fd6567f520a5e8b0d6262f05c645f02e69a1.html#h2-0-79).

According to https://github.com/openssh/openssh-portable/commit/d018b2e9c88f6669c68f3343dbbf53e6084e8ff7, this implementation was adapted from the one included in sudo. However, I wasn't able to find a release version of sudo (https://www.sudo.ws/dist/OLD/) that contains "__unused static const char rcsid[] = "$Sudo: closefrom.c,v 1.11 2006/08/17 15:26:54 millert Exp $";". (Apparently, it must have existed some time between v1.6.8 and v1.6.9.)
Comment 1 Damien Miller 2018-07-27 14:20:41 AEST
Thanks, I just committed this.
Comment 2 Damien Miller 2018-10-19 17:17:19 AEDT
Close RESOLVED bugs with the release of openssh-8.0