diff options
author | deraadt@openbsd.org <deraadt@openbsd.org> | 2019-06-28 13:35:04 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-07-05 11:10:39 +1000 |
commit | 4d28fa78abce2890e136281950633fae2066cc29 (patch) | |
tree | 33226ec64ced661bb7e40005e30744b68fa59a80 /scp.c | |
parent | e8c974043c1648eab0ad67a7ba6a3e444fe79d2d (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 'scp.c')
-rw-r--r-- | scp.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: scp.c,v 1.204 2019/02/10 11:15:52 djm Exp $ */ | 1 | /* $OpenBSD: scp.c,v 1.205 2019/06/28 13:35:04 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * scp - secure remote copy. This is basically patched BSD rcp which | 3 | * scp - secure remote copy. This is basically patched BSD rcp which |
4 | * uses ssh to do the data transfer (instead of using rcmd). | 4 | * uses ssh to do the data transfer (instead of using rcmd). |
@@ -253,13 +253,13 @@ do_cmd(char *host, char *remuser, int port, char *cmd, int *fdin, int *fdout) | |||
253 | * Reserve two descriptors so that the real pipes won't get | 253 | * Reserve two descriptors so that the real pipes won't get |
254 | * descriptors 0 and 1 because that will screw up dup2 below. | 254 | * descriptors 0 and 1 because that will screw up dup2 below. |
255 | */ | 255 | */ |
256 | if (pipe(reserved) < 0) | 256 | if (pipe(reserved) == -1) |
257 | fatal("pipe: %s", strerror(errno)); | 257 | fatal("pipe: %s", strerror(errno)); |
258 | 258 | ||
259 | /* Create a socket pair for communicating with ssh. */ | 259 | /* Create a socket pair for communicating with ssh. */ |
260 | if (pipe(pin) < 0) | 260 | if (pipe(pin) == -1) |
261 | fatal("pipe: %s", strerror(errno)); | 261 | fatal("pipe: %s", strerror(errno)); |
262 | if (pipe(pout) < 0) | 262 | if (pipe(pout) == -1) |
263 | fatal("pipe: %s", strerror(errno)); | 263 | fatal("pipe: %s", strerror(errno)); |
264 | 264 | ||
265 | /* Free the reserved descriptors. */ | 265 | /* Free the reserved descriptors. */ |
@@ -1075,13 +1075,13 @@ source(int argc, char **argv) | |||
1075 | len = strlen(name); | 1075 | len = strlen(name); |
1076 | while (len > 1 && name[len-1] == '/') | 1076 | while (len > 1 && name[len-1] == '/') |
1077 | name[--len] = '\0'; | 1077 | name[--len] = '\0'; |
1078 | if ((fd = open(name, O_RDONLY|O_NONBLOCK, 0)) < 0) | 1078 | if ((fd = open(name, O_RDONLY|O_NONBLOCK, 0)) == -1) |
1079 | goto syserr; | 1079 | goto syserr; |
1080 | if (strchr(name, '\n') != NULL) { | 1080 | if (strchr(name, '\n') != NULL) { |
1081 | strnvis(encname, name, sizeof(encname), VIS_NL); | 1081 | strnvis(encname, name, sizeof(encname), VIS_NL); |
1082 | name = encname; | 1082 | name = encname; |
1083 | } | 1083 | } |
1084 | if (fstat(fd, &stb) < 0) { | 1084 | if (fstat(fd, &stb) == -1) { |
1085 | syserr: run_err("%s: %s", name, strerror(errno)); | 1085 | syserr: run_err("%s: %s", name, strerror(errno)); |
1086 | goto next; | 1086 | goto next; |
1087 | } | 1087 | } |
@@ -1155,7 +1155,7 @@ next: if (fd != -1) { | |||
1155 | unset_nonblock(remout); | 1155 | unset_nonblock(remout); |
1156 | 1156 | ||
1157 | if (fd != -1) { | 1157 | if (fd != -1) { |
1158 | if (close(fd) < 0 && !haderr) | 1158 | if (close(fd) == -1 && !haderr) |
1159 | haderr = errno; | 1159 | haderr = errno; |
1160 | fd = -1; | 1160 | fd = -1; |
1161 | } | 1161 | } |
@@ -1419,14 +1419,14 @@ sink(int argc, char **argv, const char *src) | |||
1419 | /* Handle copying from a read-only | 1419 | /* Handle copying from a read-only |
1420 | directory */ | 1420 | directory */ |
1421 | mod_flag = 1; | 1421 | mod_flag = 1; |
1422 | if (mkdir(np, mode | S_IRWXU) < 0) | 1422 | if (mkdir(np, mode | S_IRWXU) == -1) |
1423 | goto bad; | 1423 | goto bad; |
1424 | } | 1424 | } |
1425 | vect[0] = xstrdup(np); | 1425 | vect[0] = xstrdup(np); |
1426 | sink(1, vect, src); | 1426 | sink(1, vect, src); |
1427 | if (setimes) { | 1427 | if (setimes) { |
1428 | setimes = 0; | 1428 | setimes = 0; |
1429 | if (utimes(vect[0], tv) < 0) | 1429 | if (utimes(vect[0], tv) == -1) |
1430 | run_err("%s: set times: %s", | 1430 | run_err("%s: set times: %s", |
1431 | vect[0], strerror(errno)); | 1431 | vect[0], strerror(errno)); |
1432 | } | 1432 | } |
@@ -1437,7 +1437,7 @@ sink(int argc, char **argv, const char *src) | |||
1437 | } | 1437 | } |
1438 | omode = mode; | 1438 | omode = mode; |
1439 | mode |= S_IWUSR; | 1439 | mode |= S_IWUSR; |
1440 | if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) < 0) { | 1440 | if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) == -1) { |
1441 | bad: run_err("%s: %s", np, strerror(errno)); | 1441 | bad: run_err("%s: %s", np, strerror(errno)); |
1442 | continue; | 1442 | continue; |
1443 | } | 1443 | } |
@@ -1527,7 +1527,7 @@ bad: run_err("%s: %s", np, strerror(errno)); | |||
1527 | stop_progress_meter(); | 1527 | stop_progress_meter(); |
1528 | if (setimes && wrerr == NO) { | 1528 | if (setimes && wrerr == NO) { |
1529 | setimes = 0; | 1529 | setimes = 0; |
1530 | if (utimes(np, tv) < 0) { | 1530 | if (utimes(np, tv) == -1) { |
1531 | run_err("%s: set times: %s", | 1531 | run_err("%s: set times: %s", |
1532 | np, strerror(errno)); | 1532 | np, strerror(errno)); |
1533 | wrerr = DISPLAYED; | 1533 | wrerr = DISPLAYED; |
@@ -1681,7 +1681,7 @@ allocbuf(BUF *bp, int fd, int blksize) | |||
1681 | #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE | 1681 | #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE |
1682 | struct stat stb; | 1682 | struct stat stb; |
1683 | 1683 | ||
1684 | if (fstat(fd, &stb) < 0) { | 1684 | if (fstat(fd, &stb) == -1) { |
1685 | run_err("fstat: %s", strerror(errno)); | 1685 | run_err("fstat: %s", strerror(errno)); |
1686 | return (0); | 1686 | return (0); |
1687 | } | 1687 | } |