| Summary: | ssh-keygen fails to create .ssh directory when filename of key file contains multiple slashes | ||
|---|---|---|---|
| Product: | Portable OpenSSH | Reporter: | B S Srinidhi <srinidhi.bs> |
| Component: | ssh-keygen | Assignee: | Assigned to nobody <unassigned-bugs> |
| Status: | CLOSED WONTFIX | ||
| Severity: | normal | CC: | djm |
| Priority: | P2 | ||
| Version: | 5.2p1 | ||
| Hardware: | All | ||
| OS: | Linux | ||
|
Description
B S Srinidhi
2010-06-20 05:23:10 AEST
It looks like the following code snippet might be the cause:
1896: /* Create ~/.ssh directory if it doesn't already exist. */
1897: snprintf(dotsshdir, sizeof dotsshdir, "%s/%s",
1898: pw->pw_dir, _PATH_SSH_USER_DIR);
1899: if (strstr(identity_file, dotsshdir) != NULL) {
From: http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/ssh-keygen.c?annotate=1.190
dotsshdir is expected to be a substring of identity_file. I think before
calling strstr() on the 2 strings, identity_file should be canonicalized
- either by realpath() or canonicalize_file_name()
On the same note, ssh-keygen will fail if the identity_file contains a relative path:
# su - foo -c "ssh-keygen -t rsa -f /home/foo/bin/../.ssh/id_rsa -N ''"
Generating public/private rsa key pair.
open /home/foo/bin/../.ssh/id_rsa failed: No such file or directory.
Saving the key failed: /home/foo/bin/../.ssh/id_rsa.
If you are explicitly passing a path to ssh-keygen then don't count on it to create the directory components for you. I don't think this is worth complicating our code to fix. Move resolved bugs to CLOSED after 5.7 release |