summaryrefslogtreecommitdiff
path: root/authfile.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 /authfile.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 'authfile.c')
-rw-r--r--authfile.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/authfile.c b/authfile.c
index b1c92f4ad..2166c1689 100644
--- a/authfile.c
+++ b/authfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: authfile.c,v 1.131 2018/09/21 12:20:12 djm Exp $ */ 1/* $OpenBSD: authfile.c,v 1.132 2019/06/28 13:35:04 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved.
4 * 4 *
@@ -57,7 +57,7 @@ sshkey_save_private_blob(struct sshbuf *keybuf, const char *filename)
57{ 57{
58 int fd, oerrno; 58 int fd, oerrno;
59 59
60 if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) 60 if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600)) == -1)
61 return SSH_ERR_SYSTEM_ERROR; 61 return SSH_ERR_SYSTEM_ERROR;
62 if (atomicio(vwrite, fd, sshbuf_mutable_ptr(keybuf), 62 if (atomicio(vwrite, fd, sshbuf_mutable_ptr(keybuf),
63 sshbuf_len(keybuf)) != sshbuf_len(keybuf)) { 63 sshbuf_len(keybuf)) != sshbuf_len(keybuf)) {
@@ -101,7 +101,7 @@ sshkey_load_file(int fd, struct sshbuf *blob)
101 struct stat st; 101 struct stat st;
102 int r; 102 int r;
103 103
104 if (fstat(fd, &st) < 0) 104 if (fstat(fd, &st) == -1)
105 return SSH_ERR_SYSTEM_ERROR; 105 return SSH_ERR_SYSTEM_ERROR;
106 if ((st.st_mode & (S_IFSOCK|S_IFCHR|S_IFIFO)) == 0 && 106 if ((st.st_mode & (S_IFSOCK|S_IFCHR|S_IFIFO)) == 0 &&
107 st.st_size > MAX_KEY_FILE_SIZE) 107 st.st_size > MAX_KEY_FILE_SIZE)
@@ -141,7 +141,7 @@ sshkey_perm_ok(int fd, const char *filename)
141{ 141{
142 struct stat st; 142 struct stat st;
143 143
144 if (fstat(fd, &st) < 0) 144 if (fstat(fd, &st) == -1)
145 return SSH_ERR_SYSTEM_ERROR; 145 return SSH_ERR_SYSTEM_ERROR;
146 /* 146 /*
147 * if a key owned by the user is accessed, then we check the 147 * if a key owned by the user is accessed, then we check the
@@ -176,7 +176,7 @@ sshkey_load_private_type(int type, const char *filename, const char *passphrase,
176 if (commentp != NULL) 176 if (commentp != NULL)
177 *commentp = NULL; 177 *commentp = NULL;
178 178
179 if ((fd = open(filename, O_RDONLY)) < 0) { 179 if ((fd = open(filename, O_RDONLY)) == -1) {
180 if (perm_ok != NULL) 180 if (perm_ok != NULL)
181 *perm_ok = 0; 181 *perm_ok = 0;
182 return SSH_ERR_SYSTEM_ERROR; 182 return SSH_ERR_SYSTEM_ERROR;
@@ -236,7 +236,7 @@ sshkey_load_private(const char *filename, const char *passphrase,
236 if (commentp != NULL) 236 if (commentp != NULL)
237 *commentp = NULL; 237 *commentp = NULL;
238 238
239 if ((fd = open(filename, O_RDONLY)) < 0) 239 if ((fd = open(filename, O_RDONLY)) == -1)
240 return SSH_ERR_SYSTEM_ERROR; 240 return SSH_ERR_SYSTEM_ERROR;
241 if (sshkey_perm_ok(fd, filename) != 0) { 241 if (sshkey_perm_ok(fd, filename) != 0) {
242 r = SSH_ERR_KEY_BAD_PERMISSIONS; 242 r = SSH_ERR_KEY_BAD_PERMISSIONS;