summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
authorderaadt@openbsd.org <deraadt@openbsd.org>2019-06-28 13:35:04 +0000
committerDamien Miller <djm@mindrot.org>2019-07-05 11:10:39 +1000
commit4d28fa78abce2890e136281950633fae2066cc29 (patch)
tree33226ec64ced661bb7e40005e30744b68fa59a80 /ssh-keygen.c
parente8c974043c1648eab0ad67a7ba6a3e444fe79d2d (diff)
upstream: When system calls indicate an error they return -1, not
some arbitrary value < 0. errno is only updated in this case. Change all (most?) callers of syscalls to follow this better, and let's see if this strictness helps us in the future. OpenBSD-Commit-ID: 48081f00db7518e3b712a49dca06efc2a5428075
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index c95bc15cf..3aa4f5125 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.332 2019/06/21 04:21:04 djm Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.333 2019/06/28 13:35:04 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -370,7 +370,7 @@ do_convert_to(struct passwd *pw)
370 370
371 if (!have_identity) 371 if (!have_identity)
372 ask_filename(pw, "Enter file in which the key is"); 372 ask_filename(pw, "Enter file in which the key is");
373 if (stat(identity_file, &st) < 0) 373 if (stat(identity_file, &st) == -1)
374 fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); 374 fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
375 if ((r = sshkey_load_public(identity_file, &k, NULL)) != 0) 375 if ((r = sshkey_load_public(identity_file, &k, NULL)) != 0)
376 k = load_identity(identity_file); 376 k = load_identity(identity_file);
@@ -696,7 +696,7 @@ do_convert_from(struct passwd *pw)
696 696
697 if (!have_identity) 697 if (!have_identity)
698 ask_filename(pw, "Enter file in which the key is"); 698 ask_filename(pw, "Enter file in which the key is");
699 if (stat(identity_file, &st) < 0) 699 if (stat(identity_file, &st) == -1)
700 fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); 700 fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
701 701
702 switch (convert_format) { 702 switch (convert_format) {
@@ -756,7 +756,7 @@ do_print_public(struct passwd *pw)
756 756
757 if (!have_identity) 757 if (!have_identity)
758 ask_filename(pw, "Enter file in which the key is"); 758 ask_filename(pw, "Enter file in which the key is");
759 if (stat(identity_file, &st) < 0) 759 if (stat(identity_file, &st) == -1)
760 fatal("%s: %s", identity_file, strerror(errno)); 760 fatal("%s: %s", identity_file, strerror(errno));
761 prv = load_identity(identity_file); 761 prv = load_identity(identity_file);
762 if ((r = sshkey_write(prv, stdout)) != 0) 762 if ((r = sshkey_write(prv, stdout)) != 0)
@@ -854,7 +854,7 @@ fingerprint_private(const char *path)
854 struct sshkey *public = NULL; 854 struct sshkey *public = NULL;
855 int r; 855 int r;
856 856
857 if (stat(identity_file, &st) < 0) 857 if (stat(identity_file, &st) == -1)
858 fatal("%s: %s", path, strerror(errno)); 858 fatal("%s: %s", path, strerror(errno));
859 if ((r = sshkey_load_public(path, &public, &comment)) != 0) { 859 if ((r = sshkey_load_public(path, &public, &comment)) != 0) {
860 debug("load public \"%s\": %s", path, ssh_err(r)); 860 debug("load public \"%s\": %s", path, ssh_err(r));
@@ -1340,7 +1340,7 @@ do_change_passphrase(struct passwd *pw)
1340 1340
1341 if (!have_identity) 1341 if (!have_identity)
1342 ask_filename(pw, "Enter file in which the key is"); 1342 ask_filename(pw, "Enter file in which the key is");
1343 if (stat(identity_file, &st) < 0) 1343 if (stat(identity_file, &st) == -1)
1344 fatal("%s: %s", identity_file, strerror(errno)); 1344 fatal("%s: %s", identity_file, strerror(errno));
1345 /* Try to load the file with empty passphrase. */ 1345 /* Try to load the file with empty passphrase. */
1346 r = sshkey_load_private(identity_file, "", &private, &comment); 1346 r = sshkey_load_private(identity_file, "", &private, &comment);
@@ -1424,7 +1424,7 @@ do_print_resource_record(struct passwd *pw, char *fname, char *hname,
1424 1424
1425 if (fname == NULL) 1425 if (fname == NULL)
1426 fatal("%s: no filename", __func__); 1426 fatal("%s: no filename", __func__);
1427 if (stat(fname, &st) < 0) { 1427 if (stat(fname, &st) == -1) {
1428 if (errno == ENOENT) 1428 if (errno == ENOENT)
1429 return 0; 1429 return 0;
1430 fatal("%s: %s", fname, strerror(errno)); 1430 fatal("%s: %s", fname, strerror(errno));
@@ -1453,7 +1453,7 @@ do_change_comment(struct passwd *pw, const char *identity_comment)
1453 1453
1454 if (!have_identity) 1454 if (!have_identity)
1455 ask_filename(pw, "Enter file in which the key is"); 1455 ask_filename(pw, "Enter file in which the key is");
1456 if (stat(identity_file, &st) < 0) 1456 if (stat(identity_file, &st) == -1)
1457 fatal("%s: %s", identity_file, strerror(errno)); 1457 fatal("%s: %s", identity_file, strerror(errno));
1458 if ((r = sshkey_load_private(identity_file, "", 1458 if ((r = sshkey_load_private(identity_file, "",
1459 &private, &comment)) == 0) 1459 &private, &comment)) == 0)
@@ -2045,7 +2045,7 @@ do_show_cert(struct passwd *pw)
2045 2045
2046 if (!have_identity) 2046 if (!have_identity)
2047 ask_filename(pw, "Enter file in which the key is"); 2047 ask_filename(pw, "Enter file in which the key is");
2048 if (strcmp(identity_file, "-") != 0 && stat(identity_file, &st) < 0) 2048 if (strcmp(identity_file, "-") != 0 && stat(identity_file, &st) == -1)
2049 fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); 2049 fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
2050 2050
2051 path = identity_file; 2051 path = identity_file;
@@ -2472,7 +2472,7 @@ main(int argc, char **argv)
2472 pw = getpwuid(getuid()); 2472 pw = getpwuid(getuid());
2473 if (!pw) 2473 if (!pw)
2474 fatal("No user exists for uid %lu", (u_long)getuid()); 2474 fatal("No user exists for uid %lu", (u_long)getuid());
2475 if (gethostname(hostname, sizeof(hostname)) < 0) 2475 if (gethostname(hostname, sizeof(hostname)) == -1)
2476 fatal("gethostname: %s", strerror(errno)); 2476 fatal("gethostname: %s", strerror(errno));
2477 2477
2478 /* Remaining characters: Ydw */ 2478 /* Remaining characters: Ydw */
@@ -2852,11 +2852,11 @@ main(int argc, char **argv)
2852 snprintf(dotsshdir, sizeof dotsshdir, "%s/%s", 2852 snprintf(dotsshdir, sizeof dotsshdir, "%s/%s",
2853 pw->pw_dir, _PATH_SSH_USER_DIR); 2853 pw->pw_dir, _PATH_SSH_USER_DIR);
2854 if (strstr(identity_file, dotsshdir) != NULL) { 2854 if (strstr(identity_file, dotsshdir) != NULL) {
2855 if (stat(dotsshdir, &st) < 0) { 2855 if (stat(dotsshdir, &st) == -1) {
2856 if (errno != ENOENT) { 2856 if (errno != ENOENT) {
2857 error("Could not stat %s: %s", dotsshdir, 2857 error("Could not stat %s: %s", dotsshdir,
2858 strerror(errno)); 2858 strerror(errno));
2859 } else if (mkdir(dotsshdir, 0700) < 0) { 2859 } else if (mkdir(dotsshdir, 0700) == -1) {
2860 error("Could not create directory '%s': %s", 2860 error("Could not create directory '%s': %s",
2861 dotsshdir, strerror(errno)); 2861 dotsshdir, strerror(errno));
2862 } else if (!quiet) 2862 } else if (!quiet)