From 835d788017c49be8b4986b0f04686da55f2cd0da Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Fri, 28 Jun 2019 13:35:02 +0000 Subject: 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. --- src/usr.bin/openssl/apps.c | 28 ++++++++++++++-------------- src/usr.bin/openssl/s_client.c | 6 +++--- src/usr.bin/openssl/s_server.c | 4 ++-- src/usr.bin/openssl/s_socket.c | 8 ++++---- 4 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/usr.bin/openssl') diff --git a/src/usr.bin/openssl/apps.c b/src/usr.bin/openssl/apps.c index 2297b5bf2b..47e21265af 100644 --- a/src/usr.bin/openssl/apps.c +++ b/src/usr.bin/openssl/apps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.c,v 1.51 2019/02/09 15:49:21 inoguchi Exp $ */ +/* $OpenBSD: apps.c,v 1.52 2019/06/28 13:35:02 deraadt Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -1377,7 +1377,7 @@ rotate_serial(char *serialfile, char *new_suffix, char *old_suffix) goto err; } - if (rename(serialfile, opath) < 0 && + if (rename(serialfile, opath) == -1 && errno != ENOENT && errno != ENOTDIR) { BIO_printf(bio_err, "unable to rename %s to %s\n", serialfile, opath); @@ -1386,11 +1386,11 @@ rotate_serial(char *serialfile, char *new_suffix, char *old_suffix) } - if (rename(npath, serialfile) < 0) { + if (rename(npath, serialfile) == -1) { BIO_printf(bio_err, "unable to rename %s to %s\n", npath, serialfile); perror("reason"); - if (rename(opath, serialfile) < 0) { + if (rename(opath, serialfile) == -1) { BIO_printf(bio_err, "unable to rename %s to %s\n", opath, serialfile); perror("reason"); @@ -1599,18 +1599,18 @@ rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix) goto err; } - if (rename(dbfile, odbpath) < 0 && errno != ENOENT && errno != ENOTDIR) { + if (rename(dbfile, odbpath) == -1 && errno != ENOENT && errno != ENOTDIR) { BIO_printf(bio_err, "unable to rename %s to %s\n", dbfile, odbpath); perror("reason"); goto err; } - if (rename(dbpath, dbfile) < 0) { + if (rename(dbpath, dbfile) == -1) { BIO_printf(bio_err, "unable to rename %s to %s\n", dbpath, dbfile); perror("reason"); - if (rename(odbpath, dbfile) < 0) { + if (rename(odbpath, dbfile) == -1) { BIO_printf(bio_err, "unable to rename %s to %s\n", odbpath, dbfile); perror("reason"); @@ -1618,16 +1618,16 @@ rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix) goto err; } - if (rename(attrpath, oattrpath) < 0 && errno != ENOENT && errno != ENOTDIR) { + if (rename(attrpath, oattrpath) == -1 && errno != ENOENT && errno != ENOTDIR) { BIO_printf(bio_err, "unable to rename %s to %s\n", attrpath, oattrpath); perror("reason"); - if (rename(dbfile, dbpath) < 0) { + if (rename(dbfile, dbpath) == -1) { BIO_printf(bio_err, "unable to rename %s to %s\n", dbfile, dbpath); perror("reason"); } - if (rename(odbpath, dbfile) < 0) { + if (rename(odbpath, dbfile) == -1) { BIO_printf(bio_err, "unable to rename %s to %s\n", odbpath, dbfile); perror("reason"); @@ -1635,21 +1635,21 @@ rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix) goto err; } - if (rename(nattrpath, attrpath) < 0) { + if (rename(nattrpath, attrpath) == -1) { BIO_printf(bio_err, "unable to rename %s to %s\n", nattrpath, attrpath); perror("reason"); - if (rename(oattrpath, attrpath) < 0) { + if (rename(oattrpath, attrpath) == -1) { BIO_printf(bio_err, "unable to rename %s to %s\n", oattrpath, attrpath); perror("reason"); } - if (rename(dbfile, dbpath) < 0) { + if (rename(dbfile, dbpath) == -1) { BIO_printf(bio_err, "unable to rename %s to %s\n", dbfile, dbpath); perror("reason"); } - if (rename(odbpath, dbfile) < 0) { + if (rename(odbpath, dbfile) == -1) { BIO_printf(bio_err, "unable to rename %s to %s\n", odbpath, dbfile); perror("reason"); diff --git a/src/usr.bin/openssl/s_client.c b/src/usr.bin/openssl/s_client.c index e542f08481..23bf67e695 100644 --- a/src/usr.bin/openssl/s_client.c +++ b/src/usr.bin/openssl/s_client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_client.c,v 1.37 2018/11/14 06:24:21 tb Exp $ */ +/* $OpenBSD: s_client.c,v 1.38 2019/06/28 13:35:02 deraadt Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -759,7 +759,7 @@ re_start: if (SSL_version(con) == DTLS1_VERSION) { sbio = BIO_new_dgram(s, BIO_NOCLOSE); - if (getsockname(s, &peer, (void *) &peerlen) < 0) { + if (getsockname(s, &peer, (void *) &peerlen) == -1) { BIO_printf(bio_err, "getsockname:errno=%d\n", errno); shutdown(s, SHUT_RD); @@ -1013,7 +1013,7 @@ re_start: tty_on,read_tty,write_tty,read_ssl,write_ssl);*/ i = poll(pfd, 3, ptimeout); - if (i < 0) { + if (i == -1) { BIO_printf(bio_err, "bad select %d\n", errno); goto shut; diff --git a/src/usr.bin/openssl/s_server.c b/src/usr.bin/openssl/s_server.c index 4bdafaf682..a15795151f 100644 --- a/src/usr.bin/openssl/s_server.c +++ b/src/usr.bin/openssl/s_server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_server.c,v 1.30 2018/02/07 05:47:55 jsing Exp $ */ +/* $OpenBSD: s_server.c,v 1.31 2019/06/28 13:35:02 deraadt Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1512,7 +1512,7 @@ sv_body(char *hostname, int s, unsigned char *context) n = write(fileno(stdout), buf + len, i - len); } while (n == -1 && errno == EINTR); - if (n < 0) { + if (n == -1) { BIO_printf(bio_s_out, "ERROR\n"); goto err; } diff --git a/src/usr.bin/openssl/s_socket.c b/src/usr.bin/openssl/s_socket.c index 62b32d3936..5d90fad8bb 100644 --- a/src/usr.bin/openssl/s_socket.c +++ b/src/usr.bin/openssl/s_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_socket.c,v 1.10 2018/08/19 20:07:06 tb Exp $ */ +/* $OpenBSD: s_socket.c,v 1.11 2019/06/28 13:35:02 deraadt Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -107,7 +107,7 @@ init_client(int *sock, char *host, char *port, int type, int af) i = 0; i = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *) &i, sizeof(i)); - if (i < 0) { + if (i == -1) { perror("keepalive"); goto out; } @@ -251,10 +251,10 @@ do_accept(int acc_sock, int *sock, char **host) ling.l_onoff=1; ling.l_linger=0; i=setsockopt(ret,SOL_SOCKET,SO_LINGER,(char *)&ling,sizeof(ling)); - if (i < 0) { perror("linger"); return(0); } + if (i == -1) { perror("linger"); return(0); } i=0; i=setsockopt(ret,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i)); - if (i < 0) { perror("keepalive"); return(0); } + if (i == -1) { perror("keepalive"); return(0); } */ if (host == NULL) -- cgit v1.2.3-55-g6feb