diff options
58 files changed, 179 insertions, 175 deletions
diff --git a/bin/csh/set.c b/bin/csh/set.c index 954af95787b..c638d0d00d9 100644 --- a/bin/csh/set.c +++ b/bin/csh/set.c @@ -1,4 +1,4 @@ -/* $OpenBSD: set.c,v 1.22 2018/10/24 06:01:03 martijn Exp $ */ +/* $OpenBSD: set.c,v 1.23 2019/07/03 03:24:01 deraadt Exp $ */ /* $NetBSD: set.c,v 1.8 1995/03/21 18:35:52 mycroft Exp $ */ /*- @@ -329,7 +329,7 @@ putn(int n) int i; i = snprintf(number, sizeof(number), "%d", n); - if (i == -1 || i >= sizeof(number)) + if (i < 0 || i >= sizeof(number)) return (STRNULL); return (SAVE(number)); } diff --git a/bin/mt/mtrmt.c b/bin/mt/mtrmt.c index 84e4dd57b40..d1e9f1f5d19 100644 --- a/bin/mt/mtrmt.c +++ b/bin/mt/mtrmt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mtrmt.c,v 1.23 2019/06/28 13:34:59 deraadt Exp $ */ +/* $OpenBSD: mtrmt.c,v 1.24 2019/07/03 03:24:01 deraadt Exp $ */ /* $NetBSD: mtrmt.c,v 1.2 1996/03/06 06:22:07 scottr Exp $ */ /*- @@ -172,7 +172,7 @@ rmtopen(char *tape, int mode) int r; r = snprintf(buf, sizeof (buf), "O%s\n%d\n", tape, mode); - if (r == -1 || r >= sizeof buf) + if (r < 0 || r >= sizeof buf) errx(1, "tape name too long"); rmtstate = TS_OPEN; return (rmtcall(tape, buf)); @@ -213,7 +213,7 @@ rmtioctl(int cmd, int count) if (count < 0) return (-1); r = snprintf(buf, sizeof (buf), "I%d\n%d\n", cmd, count); - if (r == -1 || r >= sizeof buf) + if (r < 0 || r >= sizeof buf) errx(1, "string error during ioctl"); return (rmtcall("ioctl", buf)); } diff --git a/lib/libc/asr/asr_debug.c b/lib/libc/asr/asr_debug.c index 141517b8360..9fc5857ebde 100644 --- a/lib/libc/asr/asr_debug.c +++ b/lib/libc/asr/asr_debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asr_debug.c,v 1.25 2018/04/28 15:16:49 schwarze Exp $ */ +/* $OpenBSD: asr_debug.c,v 1.26 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -73,7 +73,7 @@ print_rr(const struct asr_dns_rr *rr, char *buf, size_t max) rr->rr_ttl, __p_class(rr->rr_class), __p_type(rr->rr_type)); - if (r == -1) { + if (r < 0 || r >= max) { buf[0] = '\0'; return (buf); } diff --git a/lib/libc/asr/getnameinfo.c b/lib/libc/asr/getnameinfo.c index a61b542e08c..7bee468dbc0 100644 --- a/lib/libc/asr/getnameinfo.c +++ b/lib/libc/asr/getnameinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnameinfo.c,v 1.8 2015/10/02 20:56:14 deraadt Exp $ */ +/* $OpenBSD: getnameinfo.c,v 1.9 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -138,7 +138,7 @@ asr_print_port(const struct sockaddr *sa, const char *proto, char *buf, size_t b } r = snprintf(buf, buflen, "%u", ntohs(port)); - if (r == -1) /* Actually, this can not happen */ + if (r < 0 || r >= buflen) /* Actually, this can not happen */ return (0); return (r); diff --git a/lib/libc/asr/getnameinfo_async.c b/lib/libc/asr/getnameinfo_async.c index 93d9a2dbea9..13c00f1c7a1 100644 --- a/lib/libc/asr/getnameinfo_async.c +++ b/lib/libc/asr/getnameinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnameinfo_async.c,v 1.13 2017/02/23 17:04:02 eric Exp $ */ +/* $OpenBSD: getnameinfo_async.c,v 1.14 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -235,7 +235,7 @@ _servname(struct asr_query *as) } r = snprintf(buf, buflen, "%u", ntohs(port)); - if (r == -1 || r >= (int)buflen) + if (r < 0 || r >= buflen) return (-1); return (0); diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index 9a8a49ed294..af866d26cc1 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getcap.c,v 1.34 2016/09/21 04:38:56 guenther Exp $ */ +/* $OpenBSD: getcap.c,v 1.35 2019/07/03 03:24:04 deraadt Exp $ */ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -251,7 +251,7 @@ getent(char **cap, u_int *len, char **db_array, FILE *fp, char *dbrecord; clen = snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); - if (clen != -1 && clen < sizeof(pbuf) && usedb && + if (clen >= 0 && clen < sizeof(pbuf) && usedb && (capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))) { opened++; retval = cdbget(capdbp, &dbrecord, name); diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 531f654fd0f..08027ed7e51 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setlocale.c,v 1.29 2018/03/29 16:39:04 schwarze Exp $ */ +/* $OpenBSD: setlocale.c,v 1.30 2019/07/03 03:24:04 deraadt Exp $ */ /* * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> * @@ -162,7 +162,7 @@ setlocale(int category, const char *locname) ic = snprintf(global_locname, sizeof(global_locname), "%s/%s/%s/%s/%s/%s", newgl[1], newgl[2], newgl[3], newgl[4], newgl[5], newgl[6]); - if (ic == -1 || ic >= sizeof(global_locname)) + if (ic < 0 || ic >= sizeof(global_locname)) global_locname[0] = '\0'; } diff --git a/lib/libc/net/inet_net_ntop.c b/lib/libc/net/inet_net_ntop.c index 652b24076e6..1f1c4bed127 100644 --- a/lib/libc/net/inet_net_ntop.c +++ b/lib/libc/net/inet_net_ntop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet_net_ntop.c,v 1.8 2015/05/14 11:52:43 jsg Exp $ */ +/* $OpenBSD: inet_net_ntop.c,v 1.9 2019/07/03 03:24:04 deraadt Exp $ */ /* * Copyright (c) 2012 by Gilles Chehade <gilles@openbsd.org> @@ -151,7 +151,7 @@ inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) return (NULL); ret = snprintf(dst, size, "%s/%d", buf, bits); - if (ret == -1 || ret >= size) { + if (ret < 0 || ret >= size) { errno = EMSGSIZE; return (NULL); } diff --git a/lib/libc/rpc/clnt_perror.c b/lib/libc/rpc/clnt_perror.c index 7ddf5b4d120..6b0222aad43 100644 --- a/lib/libc/rpc/clnt_perror.c +++ b/lib/libc/rpc/clnt_perror.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clnt_perror.c,v 1.24 2015/09/13 15:36:56 guenther Exp $ */ +/* $OpenBSD: clnt_perror.c,v 1.25 2019/07/03 03:24:04 deraadt Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -57,7 +57,7 @@ clnt_sperror(CLIENT *rpch, char *s) CLNT_GETERR(rpch, &e); ret = snprintf(str, len, "%s: %s", s, clnt_sperrno(e.re_status)); - if (ret == -1) + if (ret < 0) ret = 0; else if (ret >= len) goto truncated; @@ -83,7 +83,7 @@ clnt_sperror(CLIENT *rpch, char *s) case RPC_CANTSEND: case RPC_CANTRECV: ret = snprintf(str, len, "; errno = %s", strerror(e.re_errno)); - if (ret == -1 || ret >= len) + if (ret < 0 || ret >= len) goto truncated; break; @@ -91,13 +91,13 @@ clnt_sperror(CLIENT *rpch, char *s) ret = snprintf(str, len, "; low version = %u, high version = %u", e.re_vers.low, e.re_vers.high); - if (ret == -1 || ret >= len) + if (ret < 0 || ret >= len) goto truncated; break; case RPC_AUTHERROR: ret = snprintf(str, len, "; why = "); - if (ret == -1) + if (ret < 0) ret = 0; else if (ret >= len) goto truncated; @@ -106,13 +106,13 @@ clnt_sperror(CLIENT *rpch, char *s) err = auth_errmsg(e.re_why); if (err != NULL) { ret = snprintf(str, len, "%s", err); - if (ret == -1 || ret >= len) + if (ret < 0 || ret >= len) goto truncated; } else { ret = snprintf(str, len, "(unknown authentication error - %d)", (int) e.re_why); - if (ret == -1 || ret >= len) + if (ret < 0 || ret >= len) goto truncated; } break; @@ -121,14 +121,14 @@ clnt_sperror(CLIENT *rpch, char *s) ret = snprintf(str, len, "; low version = %u, high version = %u", e.re_vers.low, e.re_vers.high); - if (ret == -1 || ret >= len) + if (ret < 0 || ret >= len) goto truncated; break; default: /* unknown */ ret = snprintf(str, len, "; s1 = %u, s2 = %u", e.re_lb.s1, e.re_lb.s2); - if (ret == -1 || ret >= len) + if (ret < 0 || ret >= len) goto truncated; break; } diff --git a/lib/libc/time/asctime.c b/lib/libc/time/asctime.c index d2a0d19e94d..ed8de2773b9 100644 --- a/lib/libc/time/asctime.c +++ b/lib/libc/time/asctime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asctime.c,v 1.23 2015/10/24 18:13:18 guenther Exp $ */ +/* $OpenBSD: asctime.c,v 1.24 2019/07/03 03:24:04 deraadt Exp $ */ /* ** This file is in the public domain, so clarified as of ** 1996-06-05 by Arthur David Olson. @@ -99,7 +99,7 @@ asctime3(const struct tm *timeptr, char *buf, int bufsize) timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, year); - if (len != -1 && len < bufsize) { + if (len >= 0 && len < bufsize) { return buf; } else { errno = EOVERFLOW; diff --git a/lib/libcrypto/objects/obj_dat.c b/lib/libcrypto/objects/obj_dat.c index 6c50aa980aa..c0b63e4d852 100644 --- a/lib/libcrypto/objects/obj_dat.c +++ b/lib/libcrypto/objects/obj_dat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: obj_dat.c,v 1.41 2018/09/08 13:49:26 tb Exp $ */ +/* $OpenBSD: obj_dat.c,v 1.42 2019/07/03 03:24:04 deraadt Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -608,7 +608,7 @@ OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) goto err; i = snprintf(buf, buf_len, ".%s", bndec); free(bndec); - if (i == -1) + if (i < 0) goto err; if (i >= buf_len) { buf_len = 0; @@ -619,7 +619,7 @@ OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) ret += i; } else { i = snprintf(buf, buf_len, ".%lu", l); - if (i == -1) + if (i < 0) goto err; if (i >= buf_len) { buf_len = 0; diff --git a/lib/libcrypto/ts/ts_rsp_sign.c b/lib/libcrypto/ts/ts_rsp_sign.c index 9ab80160b38..6125fdd4be4 100644 --- a/lib/libcrypto/ts/ts_rsp_sign.c +++ b/lib/libcrypto/ts/ts_rsp_sign.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ts_rsp_sign.c,v 1.22 2018/05/13 15:04:05 tb Exp $ */ +/* $OpenBSD: ts_rsp_sign.c,v 1.23 2019/07/03 03:24:04 deraadt Exp $ */ /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL * project 2002. */ @@ -1001,7 +1001,7 @@ TS_RESP_set_genTime_with_precision(ASN1_GENERALIZEDTIME *asn1_time, "%04d%02d%02d%02d%02d%02d%sZ", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, usecstr); - if (rv == -1 || rv >= sizeof(genTime_str)) + if (rv < 0 || rv >= sizeof(genTime_str)) goto err; /* Now call OpenSSL to check and set our genTime value */ diff --git a/lib/libutil/uucplock.c b/lib/libutil/uucplock.c index 0ec649421ab..045566986f1 100644 --- a/lib/libutil/uucplock.c +++ b/lib/libutil/uucplock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uucplock.c,v 1.20 2019/06/28 13:32:43 deraadt Exp $ */ +/* $OpenBSD: uucplock.c,v 1.21 2019/07/03 03:24:04 deraadt Exp $ */ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -197,13 +197,15 @@ put_pid(int fd, pid_t pid) int len; len = snprintf(buf, sizeof buf, "%10ld\n", (long)pid); + if (len < 0 || len >= sizeof buf) + return 0; - if (len < sizeof buf && len != -1 && write(fd, buf, (size_t)len) == len) { - /* We don't mind too much if ftruncate() fails - see get_pid */ - ftruncate(fd, (off_t)len); - return 1; - } - return 0; + if (write(fd, buf, len) != len) + return 0; + + /* We don't mind too much if ftruncate() fails - see get_pid */ + ftruncate(fd, (off_t)len); + return 1; } static pid_t diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index eff1cd1099a..243881be9c3 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftpd.c,v 1.227 2019/06/28 13:32:53 deraadt Exp $ */ +/* $OpenBSD: ftpd.c,v 1.228 2019/07/03 03:24:04 deraadt Exp $ */ /* $NetBSD: ftpd.c,v 1.15 1995/06/03 22:46:47 mycroft Exp $ */ /* @@ -2771,7 +2771,7 @@ logxfer(char *name, off_t size, time_t start) ((guest) ? "*" : pw->pw_name), dhostname); free(vpw); - if (len == -1 || len >= sizeof(buf)) { + if (len < 0 || len >= sizeof(buf)) { if ((len = strlen(buf)) == 0) return; /* should not happen */ buf[len - 1] = '\n'; diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index b39aa872501..0a8b3fdb1d9 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.119 2019/06/22 19:47:12 krw Exp $ */ +/* $OpenBSD: options.c,v 1.120 2019/07/03 03:24:01 deraadt Exp $ */ /* DHCP options parsing and reassembly. */ @@ -362,7 +362,7 @@ code_to_name(int code) return dhcp_options[code].name; ret = snprintf(unknown, sizeof(unknown), "option-%d", code); - if (ret == -1 || ret >= (int)sizeof(unknown)) + if (ret < 0 || ret >= (int)sizeof(unknown)) return ""; return unknown; @@ -378,7 +378,7 @@ name_to_code(char *name) if (dhcp_options[code].name == NULL) { ret = snprintf(unknown, sizeof(unknown), "option-%d", code); - if (ret == -1 || ret >= (int)sizeof(unknown)) + if (ret < 0 || ret >= (int)sizeof(unknown)) return DHO_END; if (strcasecmp(unknown, name) == 0) return code; @@ -635,7 +635,7 @@ pretty_print_classless_routes(unsigned char *src, size_t srclen, } rslt = snprintf(bitsbuf, sizeof(bitsbuf), "/%d ", bits); - if (rslt == -1 || (unsigned int)rslt >= sizeof(bitsbuf)) + if (rslt < 0 || (unsigned int)rslt >= sizeof(bitsbuf)) goto bad; if (strlen(buf) > 0) @@ -897,13 +897,13 @@ pretty_print_option(unsigned int code, struct option_data *option, log_procname, fmtbuf[j]); goto toobig; } - if (opcount == -1 || opcount >= opleft) + if (opcount < 0 || opcount >= opleft) goto toobig; opleft -= opcount; op += opcount; if (j + 1 < numelem && comma != ':') { opcount = snprintf(op, opleft, " "); - if (opcount == -1 || opcount >= opleft) + if (opcount < 0 || opcount >= opleft) goto toobig; opleft -= opcount; op += opcount; @@ -911,7 +911,7 @@ pretty_print_option(unsigned int code, struct option_data *option, } if (i + 1 < numhunk) { opcount = snprintf(op, opleft, "%c", comma); - if (opcount == -1 || opcount >= opleft) + if (opcount < 0 || opcount >= opleft) goto toobig; opleft -= opcount; op += opcount; diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index fd7a2af685f..dd3589611a5 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.360 2019/04/29 18:54:12 krw Exp $ */ +/* $OpenBSD: editor.c,v 1.361 2019/07/03 03:24:01 deraadt Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller <millert@openbsd.org> @@ -1141,7 +1141,7 @@ getnumber(char *prompt, char *helpstring, u_int32_t oval, u_int32_t maxval) const char *errstr; rslt = snprintf(buf, sizeof(buf), "%u", oval); - if (rslt == -1 || (unsigned int)rslt >= sizeof(buf)) + if (rslt < 0 || (unsigned int)rslt >= sizeof(buf)) return (CMD_BADVALUE); p = getstring(prompt, helpstring, buf); @@ -1176,7 +1176,7 @@ getuint64(struct disklabel *lp, char *prompt, char *helpstring, int rslt; rslt = snprintf(buf, sizeof(buf), "%llu", oval); - if (rslt == -1 || (unsigned int)rslt >= sizeof(buf)) + if (rslt < 0 || (unsigned int)rslt >= sizeof(buf)) goto invalid; p = getstring(prompt, helpstring, buf); diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index d2920f00bea..d30db9bca72 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.62 2017/11/16 11:08:28 krw Exp $ */ +/* $OpenBSD: misc.c,v 1.63 2019/07/03 03:24:01 deraadt Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -229,7 +229,7 @@ getuint64(char *prompt, u_int64_t oval, u_int64_t minval, u_int64_t maxval) if (buf[0] == '\0') { rslt = snprintf(buf, sizeof(buf), "%llu", oval); - if (rslt == -1 || rslt >= sizeof(buf)) + if (rslt < 0 || rslt >= sizeof(buf)) errx(1, "default value too long"); } else if (buf[0] == '*' && buf[1] == '\0') { return (maxval); diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c index 9a91ebabd73..2c3f7d74276 100644 --- a/sbin/growfs/growfs.c +++ b/sbin/growfs/growfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: growfs.c,v 1.52 2019/06/28 13:32:43 deraadt Exp $ */ +/* $OpenBSD: growfs.c,v 1.53 2019/07/03 03:24:01 deraadt Exp $ */ /* * Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz * Copyright (c) 1980, 1989, 1993 The Regents of the University of California. @@ -226,7 +226,7 @@ growfs(int fsi, int fso, unsigned int Nflag) cylno < (sblock.fs_ncg - 1) ? "," : ""); if (j >= sizeof(tmpbuf)) j = sizeof(tmpbuf) - 1; - if (j == -1 || i + j >= colwidth) { + if (j < 0 || i + j >= colwidth) { printf("\n"); i = 0; } diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 80e123341cc..07b981e8352 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.403 2019/06/28 13:32:44 deraadt Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.404 2019/07/03 03:24:01 deraadt Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -5984,7 +5984,7 @@ in_getaddr(const char *s, int which) (bits = inet_net_pton(AF_INET, s, &tsin.sin_addr, sizeof(tsin.sin_addr))) != -1) { l = snprintf(p, sizeof(p), "%d", bits); - if (l >= sizeof(p) || l == -1) + if (l < 0 || l >= sizeof(p)) errx(1, "%d: bad prefixlen", bits); in_getprefix(p, MASK); memcpy(&sin->sin_addr, &tsin.sin_addr, sizeof(sin->sin_addr)); diff --git a/sbin/iked/ca.c b/sbin/iked/ca.c index 98b6b8a40f5..07dc503c8fa 100644 --- a/sbin/iked/ca.c +++ b/sbin/iked/ca.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ca.c,v 1.47 2019/02/27 06:33:56 sthen Exp $ */ +/* $OpenBSD: ca.c,v 1.48 2019/07/03 03:24:01 deraadt Exp $ */ /* * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org> @@ -589,7 +589,7 @@ ca_reload(struct iked *env) continue; if (snprintf(file, sizeof(file), "%s%s", - IKED_CA_DIR, entry->d_name) == -1) + IKED_CA_DIR, entry->d_name) < 0) continue; if (!X509_load_cert_file(store->ca_calookup, file, @@ -615,7 +615,7 @@ ca_reload(struct iked *env) continue; if (snprintf(file, sizeof(file), "%s%s", - IKED_CRL_DIR, entry->d_name) == -1) + IKED_CRL_DIR, entry->d_name) < 0) continue; if (!X509_load_crl_file(store->ca_calookup, file, @@ -688,7 +688,7 @@ ca_reload(struct iked *env) continue; if (snprintf(file, sizeof(file), "%s%s", - IKED_CERT_DIR, entry->d_name) == -1) + IKED_CERT_DIR, entry->d_name) < 0) continue; if (!X509_load_cert_file(store->ca_certlookup, file, diff --git a/sbin/ipsecctl/pfkdump.c b/sbin/ipsecctl/pfkdump.c index 77fd8182552..3ab5ea17c4c 100644 --- a/sbin/ipsecctl/pfkdump.c +++ b/sbin/ipsecctl/pfkdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkdump.c,v 1.48 2018/08/28 15:17:56 mpi Exp $ */ +/* $OpenBSD: pfkdump.c,v 1.49 2019/07/03 03:24:02 deraadt Exp $ */ /* * Copyright (c) 2003 Markus Friedl. All rights reserved. @@ -261,11 +261,11 @@ print_flags(uint32_t flags) { static char fstr[80]; struct idname *entry; - size_t len; + int len; int i, comma = 0, n; len = snprintf(fstr, sizeof(fstr), "%#x<", flags); - if (len >= sizeof(fstr)) + if (len < 0 || len >= sizeof(fstr)) return (NULL); for (i = 0; i < 32; i++) { if ((flags & (1 << i)) == 0 || @@ -273,7 +273,7 @@ print_flags(uint32_t flags) continue; n = snprintf(fstr + len, sizeof(fstr) - len - 1, comma ? ",%s" : "%s", entry->name); - if ((size_t)n >= sizeof(fstr) - len - 1) + if (n < 0 || n >= sizeof(fstr) - len - 1) return (NULL); len += n; comma = 1; diff --git a/sbin/isakmpd/policy.c b/sbin/isakmpd/policy.c index ca45fc950f2..f18e1f1a1f1 100644 --- a/sbin/isakmpd/policy.c +++ b/sbin/isakmpd/policy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: policy.c,v 1.100 2019/06/28 13:32:44 deraadt Exp $ */ +/* $OpenBSD: policy.c,v 1.101 2019/07/03 03:24:02 deraadt Exp $ */ /* $EOM: policy.c,v 1.49 2000/10/24 13:33:39 niklas Exp $ */ /* @@ -94,7 +94,7 @@ my_inet_ntop4(const in_addr_t *src, char *dst, size_t size, int normalize) len = snprintf(tmp, sizeof tmp, fmt, ((u_int8_t *)&src2)[0], ((u_int8_t *)&src2)[1], ((u_int8_t *)&src2)[2], ((u_int8_t *)&src2)[3]); - if (len == -1 || len > (int)size) { + if (len < 0 || len > (int)size) { errno = ENOSPC; return 0; } @@ -113,7 +113,7 @@ my_inet_ntop6(const unsigned char *src, char *dst, size_t size) len = snprintf(tmp, sizeof tmp, fmt, src[0], src[1], src[2], src[3], src[4], src[5], src[6], src[7], src[8], src[9], src[10], src[11], src[12], src[13], src[14], src[15]); - if (len == -1 || len > (int)size) { + if (len < 0 || len > (int)size) { errno = ENOSPC; return 0; } diff --git a/sbin/ncheck_ffs/ncheck_ffs.c b/sbin/ncheck_ffs/ncheck_ffs.c index aa12a3a1736..793fb18276b 100644 --- a/sbin/ncheck_ffs/ncheck_ffs.c +++ b/sbin/ncheck_ffs/ncheck_ffs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ncheck_ffs.c,v 1.54 2019/06/28 13:32:45 deraadt Exp $ */ +/* $OpenBSD: ncheck_ffs.c,v 1.55 2019/07/03 03:24:02 deraadt Exp $ */ /*- * Copyright (c) 1995, 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com> @@ -643,14 +643,14 @@ format_entry(const char *path, struct direct *dp) case 'I': len = snprintf(dst, size - (dst - buf), "%llu", (unsigned long long)dp->d_ino); - if (len == -1 || len >= size - (dst - buf)) + if (len < 0 || len >= size - (dst - buf)) goto expand_buf; dst += len; break; case 'P': len = snprintf(dst, size - (dst - buf), "%s/%s", path, dp->d_name); - if (len == -1 || len >= size - (dst - buf)) + if (len < 0 || len >= size - (dst - buf)) goto expand_buf; dst += len; break; diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 0350dd220ff..ed5f9c9ca87 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkfs.c,v 1.97 2016/09/01 09:27:06 otto Exp $ */ +/* $OpenBSD: mkfs.c,v 1.98 2019/07/03 03:24:02 deraadt Exp $ */ /* $NetBSD: mkfs.c,v 1.25 1995/06/18 21:35:38 cgd Exp $ */ /* @@ -567,7 +567,7 @@ mkfs(struct partition *pp, char *fsys, int fi, int fo, mode_t mfsmode, (long long)fsbtodb(&sblock, cgsblock(&sblock, cylno))); if (j >= sizeof tmpbuf) j = sizeof tmpbuf - 1; - if (j == -1 || i+j >= width) { + if (j < 0 || i+j >= width) { printf("\n"); i = 0; } diff --git a/sbin/unwind/parse.y b/sbin/unwind/parse.y index 94e6cd763ef..8a65f659bdd 100644 --- a/sbin/unwind/parse.y +++ b/sbin/unwind/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.6 2019/05/13 23:13:24 florian Exp $ */ +/* $OpenBSD: parse.y,v 1.7 2019/07/03 03:24:02 deraadt Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -354,7 +354,7 @@ forwarderoptsl : STRING { ret = snprintf(uw_forwarder->name, sizeof(uw_forwarder->name), "%s@%d", $1, (int)$3); - if (ret == -1 || (size_t)ret >= + if (ret < 0 || (size_t)ret >= sizeof(uw_forwarder->name)) { free(uw_forwarder); yyerror("forwarder %s too long", $1); @@ -381,7 +381,7 @@ forwarderoptsl : STRING { ret = snprintf(uw_forwarder->name, sizeof(uw_forwarder->name), "%s@853", $1); - if (ret == -1 || (size_t)ret >= + if (ret < 0 || (size_t)ret >= sizeof(uw_forwarder->name)) { free(uw_forwarder); yyerror("forwarder %s too long", $1); @@ -416,7 +416,7 @@ forwarderoptsl : STRING { ret = snprintf(uw_forwarder->name, sizeof(uw_forwarder->name), "%s@%d", $1, (int)$3); - if (ret == -1 || (size_t)ret >= + if (ret < 0 || (size_t)ret >= sizeof(uw_forwarder->name)) { free(uw_forwarder); yyerror("forwarder %s too long", $1); @@ -445,7 +445,7 @@ forwarderoptsl : STRING { ret = snprintf(uw_forwarder->name, sizeof(uw_forwarder->name), "%s@853#%s", $1, $4); - if (ret == -1 || (size_t)ret >= + if (ret < 0 || (size_t)ret >= sizeof(uw_forwarder->name)) { free(uw_forwarder); yyerror("forwarder %s too long", $1); @@ -480,7 +480,7 @@ forwarderoptsl : STRING { ret = snprintf(uw_forwarder->name, sizeof(uw_forwarder->name), "%s@%d#%s", $1, (int)$3, $6); - if (ret == -1 || (size_t)ret >= + if (ret < 0 || (size_t)ret >= sizeof(uw_forwarder->name)) { free(uw_forwarder); yyerror("forwarder %s too long", $1); diff --git a/usr.bin/cdio/cdio.c b/usr.bin/cdio/cdio.c index 023529d3f70..af5a26c16a0 100644 --- a/usr.bin/cdio/cdio.c +++ b/usr.bin/cdio/cdio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cdio.c,v 1.77 2019/06/28 13:35:00 deraadt Exp $ */ +/* $OpenBSD: cdio.c,v 1.78 2019/07/03 03:24:02 deraadt Exp $ */ /* Copyright (c) 1995 Serge V. Vakulenko * All rights reserved. @@ -285,7 +285,7 @@ main(int argc, char **argv) len = snprintf(p, buf + sizeof buf - p, "%s%s", (p > buf) ? " " : "", *argv); - if (len == -1 || len >= buf + sizeof buf - p) + if (len < 0 || len >= buf + sizeof buf - p) errx(1, "argument list too long."); p += len; diff --git a/usr.bin/doas/doas.c b/usr.bin/doas/doas.c index c52d09cbcda..af57f429908 100644 --- a/usr.bin/doas/doas.c +++ b/usr.bin/doas/doas.c @@ -1,4 +1,4 @@ -/* $OpenBSD: doas.c,v 1.79 2019/06/29 22:35:37 tedu Exp $ */ +/* $OpenBSD: doas.c,v 1.80 2019/07/03 03:24:02 deraadt Exp $ */ /* * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org> * @@ -267,7 +267,7 @@ unveilcommands(const char *ipath, const char *cmd) if (cp) { int r = snprintf(buf, sizeof buf, "%s/%s", cp, cmd); - if (r != -1 && r < sizeof buf) { + if (r >= 0 && r < sizeof buf) { if (unveil(buf, "x") != -1) unveils++; } diff --git a/usr.bin/finger/util.c b/usr.bin/finger/util.c index 9961d6aea0d..7bf6d5d1ef0 100644 --- a/usr.bin/finger/util.c +++ b/usr.bin/finger/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.35 2019/06/28 13:35:01 deraadt Exp $ */ +/* $OpenBSD: util.c,v 1.36 2019/07/03 03:24:02 deraadt Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -120,7 +120,7 @@ userinfo(PERSON *pn, struct passwd *pw) } len = snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_MAILSPOOL, pw->pw_name); - if (len != -1 && len < sizeof(tbuf)) { + if (len >= 0 && len < sizeof(tbuf)) { if (stat(tbuf, &sb) < 0) { if (errno != ENOENT) { warn("%s", tbuf); diff --git a/usr.bin/mg/cscope.c b/usr.bin/mg/cscope.c index 72aaa64dadc..18042d30e54 100644 --- a/usr.bin/mg/cscope.c +++ b/usr.bin/mg/cscope.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cscope.c,v 1.17 2017/10/12 14:12:00 florian Exp $ */ +/* $OpenBSD: cscope.c,v 1.18 2019/07/03 03:24:02 deraadt Exp $ */ /* * This file is in the public domain. @@ -634,7 +634,7 @@ csexists(const char *cmd) dir[--dlen] = '\0'; /* strip trailing '/' */ len = snprintf(fname, sizeof(fname), "%s/%s", dir, cmd); - if (len == -1 || len >= sizeof(fname)) { + if (len < 0 || len >= sizeof(fname)) { dobeep(); ewprintf("path too long"); goto cleanup; diff --git a/usr.bin/nc/socks.c b/usr.bin/nc/socks.c index 856c3e74463..39e4331be39 100644 --- a/usr.bin/nc/socks.c +++ b/usr.bin/nc/socks.c @@ -1,4 +1,4 @@ -/* $OpenBSD: socks.c,v 1.27 2019/01/10 12:44:54 mestre Exp $ */ +/* $OpenBSD: socks.c,v 1.28 2019/07/03 03:24:02 deraadt Exp $ */ /* * Copyright (c) 1999 Niklas Hallqvist. All rights reserved. @@ -334,7 +334,7 @@ socks_connect(const char *host, const char *port, "CONNECT %s:%d HTTP/1.0\r\n", host, ntohs(serverport)); } - if (r == -1 || (size_t)r >= sizeof(buf)) + if (r < 0 || (size_t)r >= sizeof(buf)) errx(1, "hostname too long"); r = strlen(buf); @@ -357,7 +357,7 @@ socks_connect(const char *host, const char *port, errx(1, "Proxy username/password too long"); r = snprintf(buf, sizeof(buf), "Proxy-Authorization: " "Basic %s\r\n", resp); - if (r == -1 || (size_t)r >= sizeof(buf)) + if (r < 0 || (size_t)r >= sizeof(buf)) errx(1, "Proxy auth response too long"); r = strlen(buf); if ((cnt = atomicio(vwrite, proxyfd, buf, r)) != r) diff --git a/usr.bin/openssl/apps.c b/usr.bin/openssl/apps.c index 47e21265af2..39ce7a5f342 100644 --- a/usr.bin/openssl/apps.c +++ b/usr.bin/openssl/apps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apps.c,v 1.52 2019/06/28 13:35:02 deraadt Exp $ */ +/* $OpenBSD: apps.c,v 1.53 2019/07/03 03:24:02 deraadt Exp $ */ /* * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> * @@ -1328,7 +1328,7 @@ save_serial(char *serialfile, char *suffix, BIGNUM *serial, else n = snprintf(serialpath, sizeof serialpath, "%s.%s", serialfile, suffix); - if (n == -1 || n >= sizeof(serialpath)) { + if (n < 0 || n >= sizeof(serialpath)) { BIO_printf(bio_err, "serial too long\n"); goto err; } diff --git a/usr.bin/openssl/ca.c b/usr.bin/openssl/ca.c index 2e798495723..ac183f28bf8 100644 --- a/usr.bin/openssl/ca.c +++ b/usr.bin/openssl/ca.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ca.c,v 1.26 2018/02/07 05:47:55 jsing Exp $ */ +/* $OpenBSD: ca.c,v 1.27 2019/07/03 03:24:02 deraadt Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1109,7 +1109,7 @@ ca_main(int argc, char **argv) k = snprintf(pempath, sizeof(pempath), "%s/%s.pem", outdir, serialstr); free(serialstr); - if (k == -1 || k >= sizeof(pempath)) { + if (k < 0 || k >= sizeof(pempath)) { BIO_printf(bio_err, "certificate file name too long\n"); goto err; diff --git a/usr.bin/openssl/req.c b/usr.bin/openssl/req.c index c5cae4df897..6b7dfb98b98 100644 --- a/usr.bin/openssl/req.c +++ b/usr.bin/openssl/req.c @@ -1,4 +1,4 @@ -/* $OpenBSD: req.c,v 1.15 2018/02/07 05:47:55 jsing Exp $ */ +/* $OpenBSD: req.c,v 1.16 2019/07/03 03:24:02 deraadt Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1030,7 +1030,7 @@ prompt_info(X509_REQ * req, if ((nid = OBJ_txt2nid(type)) == NID_undef) goto start; ret = snprintf(buf, sizeof buf, "%s_default", v->name); - if (ret == -1 || ret >= sizeof(buf)) { + if (ret < 0 || ret >= sizeof(buf)) { BIO_printf(bio_err, "Name '%s' too long for default\n", v->name); return 0; @@ -1040,7 +1040,7 @@ prompt_info(X509_REQ * req, def = ""; } ret = snprintf(buf, sizeof buf, "%s_value", v->name); - if (ret == -1 || ret >= sizeof(buf)) { + if (ret < 0 || ret >= sizeof(buf)) { BIO_printf(bio_err, "Name '%s' too long for value\n", v->name); return 0; @@ -1050,7 +1050,7 @@ prompt_info(X509_REQ * req, value = NULL; } ret = snprintf(buf, sizeof buf, "%s_min", v->name); - if (ret == -1 || ret >= sizeof(buf)) { + if (ret < 0 || ret >= sizeof(buf)) { BIO_printf(bio_err, "Name '%s' too long for min\n", v->name); return 0; @@ -1060,7 +1060,7 @@ prompt_info(X509_REQ * req, n_min = -1; } ret = snprintf(buf, sizeof buf, "%s_max", v->name); - if (ret == -1 || ret >= sizeof(buf)) { + if (ret < 0 || ret >= sizeof(buf)) { BIO_printf(bio_err, "Name '%s' too long for max\n", v->name); return 0; @@ -1098,7 +1098,7 @@ start2: for (;;) { if ((nid = OBJ_txt2nid(type)) == NID_undef) goto start2; ret = snprintf(buf, sizeof buf, "%s_default", type); - if (ret == -1 || ret >= sizeof(buf)) { + if (ret < 0 || ret >= sizeof(buf)) { BIO_printf(bio_err, "Name '%s' too long for default\n", v->name); return 0; @@ -1109,7 +1109,7 @@ start2: for (;;) { def = ""; } ret = snprintf(buf, sizeof buf, "%s_value", type); - if (ret == -1 || ret >= sizeof(buf)) { + if (ret < 0 || ret >= sizeof(buf)) { BIO_printf(bio_err, "Name '%s' too long for value\n", v->name); return 0; @@ -1120,7 +1120,7 @@ start2: for (;;) { value = NULL; } ret = snprintf(buf, sizeof buf, "%s_min", type); - if (ret == -1 || ret >= sizeof(buf)) { + if (ret < 0 || ret >= sizeof(buf)) { BIO_printf(bio_err, "Name '%s' too long for min\n", v->name); return 0; @@ -1130,7 +1130,7 @@ start2: for (;;) { n_min = -1; } ret = snprintf(buf, sizeof buf, "%s_max", type); - if (ret == -1 || ret >= sizeof(buf)) { + if (ret < 0 || ret >= sizeof(buf)) { BIO_printf(bio_err, "Name '%s' too long for max\n", v->name); return 0; diff --git a/usr.bin/openssl/s_time.c b/usr.bin/openssl/s_time.c index 1506ca356ac..3263a2dff36 100644 --- a/usr.bin/openssl/s_time.c +++ b/usr.bin/openssl/s_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_time.c,v 1.32 2018/09/17 15:37:35 cheloha Exp $ */ +/* $OpenBSD: s_time.c,v 1.33 2019/07/03 03:24:02 deraadt Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -377,7 +377,7 @@ run_test(SSL *scon) if (s_time_config.www_path != NULL) { retval = snprintf(buf, sizeof buf, "GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); - if (retval == -1 || retval >= sizeof buf) { + if (retval < 0 || retval >= sizeof buf) { fprintf(stderr, "URL too long\n"); return 0; } diff --git a/usr.bin/signify/signify.c b/usr.bin/signify/signify.c index 08f684a4676..fb5f0b2d920 100644 --- a/usr.bin/signify/signify.c +++ b/usr.bin/signify/signify.c @@ -1,4 +1,4 @@ -/* $OpenBSD: signify.c,v 1.131 2019/03/23 07:10:06 tedu Exp $ */ +/* $OpenBSD: signify.c,v 1.132 2019/07/03 03:24:02 deraadt Exp $ */ /* * Copyright (c) 2013 Ted Unangst <tedu@openbsd.org> * @@ -330,7 +330,7 @@ generate(const char *pubkeyfile, const char *seckeyfile, int rounds, explicit_bzero(xorkey, sizeof(xorkey)); nr = snprintf(commentbuf, sizeof(commentbuf), "%s secret key", comment); - if (nr == -1 || nr >= sizeof(commentbuf)) + if (nr < 0 || nr >= sizeof(commentbuf)) errx(1, "comment too long"); writekeyfile(seckeyfile, commentbuf, &enckey, sizeof(enckey), O_EXCL, 0600); @@ -339,7 +339,7 @@ generate(const char *pubkeyfile, const char *seckeyfile, int rounds, memcpy(pubkey.pkalg, PKALG, 2); memcpy(pubkey.keynum, keynum, KEYNUMLEN); nr = snprintf(commentbuf, sizeof(commentbuf), "%s public key", comment); - if (nr == -1 || nr >= sizeof(commentbuf)) + if (nr < 0 || nr >= sizeof(commentbuf)) errx(1, "comment too long"); writekeyfile(pubkeyfile, commentbuf, &pubkey, sizeof(pubkey), O_EXCL, 0666); @@ -403,7 +403,7 @@ createsig(const char *seckeyfile, const char *msgfile, uint8_t *msg, nr = snprintf(sigcomment, sizeof(sigcomment), VERIFYWITH "%.*s.pub", (int)strlen(keyname) - 4, keyname); } - if (nr == -1 || nr >= sizeof(sigcomment)) + if (nr < 0 || nr >= sizeof(sigcomment)) errx(1, "comment too long"); if (memcmp(enckey.kdfalg, KDFALG, 2) != 0) @@ -858,7 +858,7 @@ main(int argc, char **argv) usage("must specify sigfile with - message"); nr = snprintf(sigfilebuf, sizeof(sigfilebuf), "%s.sig", msgfile); - if (nr == -1 || nr >= sizeof(sigfilebuf)) + if (nr < 0 || nr >= sizeof(sigfilebuf)) errx(1, "path too long"); sigfile = sigfilebuf; } diff --git a/usr.bin/ssh/moduli.c b/usr.bin/ssh/moduli.c index 278ef27d78c..f558a53a090 100644 --- a/usr.bin/ssh/moduli.c +++ b/usr.bin/ssh/moduli.c @@ -1,4 +1,4 @@ -/* $OpenBSD: moduli.c,v 1.34 2019/01/23 09:49:00 dtucker Exp $ */ +/* $OpenBSD: moduli.c,v 1.35 2019/07/03 03:24:02 deraadt Exp $ */ /* * Copyright 1994 Phil Karn <karn@qualcomm.com> * Copyright 1996-1998, 2003 William Allen Simpson <wsimpson@greendragon.com> @@ -447,7 +447,7 @@ write_checkpoint(char *cpfile, u_int32_t lineno) int r; r = snprintf(tmp, sizeof(tmp), "%s.XXXXXXXXXX", cpfile); - if (r == -1 || r >= PATH_MAX) { + if (r < 0 || r >= PATH_MAX) { logit("write_checkpoint: temp pathname too long"); return; } diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index 0c4a1daeb12..97ba3977ab8 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.58 2018/11/28 22:00:30 kn Exp $ */ +/* $OpenBSD: display.c,v 1.59 2019/07/03 03:24:02 deraadt Exp $ */ /* * Top users/processes display for Unix @@ -728,7 +728,7 @@ static void summary_format(char *buf, size_t left, int *numbers, char **names) { char *p, *thisname; - size_t len; + int len; int num; /* format each number followed by its string */ @@ -750,7 +750,7 @@ summary_format(char *buf, size_t left, int *numbers, char **names) COPYLEFT(p, thisname + 1); } else if (num > 0) { len = snprintf(p, left, "%d%s", num, thisname); - if (len == (size_t)-1 || len >= left) + if (len < 0 || len >= left) return; p += len; left -= len; diff --git a/usr.bin/xargs/strnsubst.c b/usr.bin/xargs/strnsubst.c index efb5a95fc09..a26edc57cc7 100644 --- a/usr.bin/xargs/strnsubst.c +++ b/usr.bin/xargs/strnsubst.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strnsubst.c,v 1.6 2017/01/03 21:47:37 tedu Exp $ */ +/* $OpenBSD: strnsubst.c,v 1.7 2019/07/03 03:24:02 deraadt Exp $ */ /* $FreeBSD: strnsubst.c,v 1.6 2002/06/22 12:58:42 jmallett Exp $ */ /* @@ -55,7 +55,7 @@ strnsubst(char **str, const char *match, const char *replstr, size_t maxsize) break; n = snprintf(s2 + s2len, maxsize - s2len, "%.*s%s", (int)(this - s1), s1, replstr); - if (n == -1 || n + s2len + strlen(this + matchlen) >= maxsize) + if (n < 0 || n + s2len + strlen(this + matchlen) >= maxsize) break; /* out of room */ s2len += n; s1 = this + matchlen; diff --git a/usr.sbin/bgpd/util.c b/usr.sbin/bgpd/util.c index 4ec98fd9b16..44e6cd151fd 100644 --- a/usr.sbin/bgpd/util.c +++ b/usr.sbin/bgpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.50 2019/06/17 13:35:43 claudio Exp $ */ +/* $OpenBSD: util.c,v 1.51 2019/07/03 03:24:02 deraadt Exp $ */ /* * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org> @@ -104,7 +104,7 @@ log_as(u_int32_t as) { static char buf[11]; /* "4294967294\0" */ - if (snprintf(buf, sizeof(buf), "%u", as) == -1) + if (snprintf(buf, sizeof(buf), "%u", as) < 0) return ("?"); return (buf); @@ -206,7 +206,7 @@ aspath_snprint(char *buf, size_t size, void *data, u_int16_t len) { #define UPDATE() \ do { \ - if (r == -1) \ + if (r < 0) \ return (-1); \ total_size += r; \ if ((unsigned int)r < size) { \ diff --git a/usr.sbin/cron/atrun.c b/usr.sbin/cron/atrun.c index d03eee04dbb..ca5f307b9d7 100644 --- a/usr.sbin/cron/atrun.c +++ b/usr.sbin/cron/atrun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: atrun.c,v 1.50 2019/06/28 13:32:47 deraadt Exp $ */ +/* $OpenBSD: atrun.c,v 1.51 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2002-2003 Todd C. Miller <millert@openbsd.org> @@ -189,7 +189,7 @@ atrun(at_db *db, double batch_maxload, time_t now) len = snprintf(atfile, sizeof(atfile), "%lld.%c", (long long)job->run_time, job->queue); - if (len >= sizeof(atfile)) { + if (len < 0 || len >= sizeof(atfile)) { TAILQ_REMOVE(&db->jobs, job, entries); free(job); continue; @@ -234,7 +234,9 @@ atrun(at_db *db, double batch_maxload, time_t now) ) { len = snprintf(atfile, sizeof(atfile), "%lld.%c", (long long)batch->run_time, batch->queue); - if (len < sizeof(atfile)) + if (len < 0 || len >= sizeof(atfile)) + ; + else run_job(batch, dfd, atfile); TAILQ_REMOVE(&db->jobs, batch, entries); free(job); diff --git a/usr.sbin/hostapd/hostapd.c b/usr.sbin/hostapd/hostapd.c index 49085569573..0371693d013 100644 --- a/usr.sbin/hostapd/hostapd.c +++ b/usr.sbin/hostapd/hostapd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hostapd.c,v 1.40 2019/06/28 13:32:47 deraadt Exp $ */ +/* $OpenBSD: hostapd.c,v 1.41 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2004, 2005 Reyk Floeter <reyk@openbsd.org> @@ -109,7 +109,7 @@ hostapd_printf(const char *fmt, ...) goto va_flush; if (strlcpy(newfmt + n, fmt, sizeof(newfmt) - n) >= sizeof(newfmt) - n) goto va_flush; - if (vsnprintf(printbuf, sizeof(printbuf), newfmt, ap) == -1) + if (vsnprintf(printbuf, sizeof(printbuf), newfmt, ap) < 0) goto va_flush; va_end(ap); diff --git a/usr.sbin/identd/identd.c b/usr.sbin/identd/identd.c index f0ffc612499..b14d8dc2970 100644 --- a/usr.sbin/identd/identd.c +++ b/usr.sbin/identd/identd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: identd.c,v 1.39 2018/01/05 08:13:31 mpi Exp $ */ +/* $OpenBSD: identd.c,v 1.40 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2013 David Gwynne <dlg@openbsd.org> @@ -469,7 +469,7 @@ parent_noident(struct ident_resolver *r, struct passwd *pw) int rv; rv = snprintf(path, sizeof(path), "%s/%s", pw->pw_dir, DOTNOIDENT); - if (rv == -1 || rv >= sizeof(path)) { + if (rv < 0 || rv >= sizeof(path)) { r->error = E_UNKNOWN; return; } diff --git a/usr.sbin/installboot/util.c b/usr.sbin/installboot/util.c index 305362f3a1c..ba5ee2f0e9c 100644 --- a/usr.sbin/installboot/util.c +++ b/usr.sbin/installboot/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.13 2018/11/07 04:51:56 miko Exp $ */ +/* $OpenBSD: util.c,v 1.14 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> @@ -107,7 +107,7 @@ fileprefix(const char *base, const char *path) return (NULL); } n = snprintf(s, PATH_MAX, "%s/%s", base, path); - if (n < 1 || n >= PATH_MAX) { + if (n < 0 || n >= PATH_MAX) { warn("snprintf"); goto err; } @@ -124,7 +124,7 @@ fileprefix(const char *base, const char *path) goto err; } n = snprintf(s, PATH_MAX, "%s/%s", r, b); - if (n < 1 || n >= PATH_MAX) { + if (n < 0 || n >= PATH_MAX) { warn("snprintf"); goto err; } diff --git a/usr.sbin/iscsid/pdu.c b/usr.sbin/iscsid/pdu.c index d498882d67c..37e2f81d543 100644 --- a/usr.sbin/iscsid/pdu.c +++ b/usr.sbin/iscsid/pdu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pdu.c,v 1.11 2015/12/05 06:38:18 mmcc Exp $ */ +/* $OpenBSD: pdu.c,v 1.12 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org> @@ -75,7 +75,7 @@ text_to_pdu(struct kvp *k, struct pdu *p) nk = 0; while(k[nk].key) { n = snprintf(s, rem, "%s=%s", k[nk].key, k[nk].value); - if (n == -1 || (size_t)n >= rem) + if (n < 0 || (size_t)n >= rem) fatalx("text_to_pdu"); rem -= n + 1; s += n + 1; diff --git a/usr.sbin/ldapd/util.c b/usr.sbin/ldapd/util.c index eb72d949dcb..cc94ebf74d2 100644 --- a/usr.sbin/ldapd/util.c +++ b/usr.sbin/ldapd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.10 2018/05/15 11:19:21 reyk Exp $ */ +/* $OpenBSD: util.c,v 1.11 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2009 Martin Hedenfalk <martin@bzero.se> @@ -43,7 +43,7 @@ bsnprintf(char *str, size_t size, const char *format, ...) va_start(ap, format); ret = vsnprintf(str, size, format, ap); va_end(ap); - if (ret == -1 || ret >= (int)size) + if (ret < 0 || ret >= size) return 0; return 1; diff --git a/usr.sbin/lpd/printer.c b/usr.sbin/lpd/printer.c index 7782b4c5307..b6743f2a9c7 100644 --- a/usr.sbin/lpd/printer.c +++ b/usr.sbin/lpd/printer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printer.c,v 1.1 2018/04/27 16:14:37 eric Exp $ */ +/* $OpenBSD: printer.c,v 1.2 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2017 Eric Faurot <eric@openbsd.org> @@ -848,7 +848,7 @@ sendcmd(const char *fmt, ...) len = vsnprintf(line, sizeof(line), fmt, ap); va_end(ap); - if (len == -1) { + if (len < 0) { log_warn("%s: vsnprintf", __func__); return -1; } diff --git a/usr.sbin/lpr/common_source/rmjob.c b/usr.sbin/lpr/common_source/rmjob.c index 0479e222003..69945619cb4 100644 --- a/usr.sbin/lpr/common_source/rmjob.c +++ b/usr.sbin/lpr/common_source/rmjob.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rmjob.c,v 1.23 2016/01/12 23:35:13 tb Exp $ */ +/* $OpenBSD: rmjob.c,v 1.24 2019/07/03 03:24:03 deraadt Exp $ */ /* $NetBSD: rmjob.c,v 1.16 2000/04/16 14:43:58 mrg Exp $ */ /* @@ -339,7 +339,7 @@ rmremote(void) /* the trailing space will be replaced with a newline later */ n = snprintf(buf, sizeof(buf), "\5%s %s ", RP, all ? "-all" : person); - if (n == -1 || n >= sizeof(buf)) + if (n < 0 || n >= sizeof(buf)) goto bad; cp = buf + n; for (i = 0; i < users; i++) { @@ -352,7 +352,7 @@ rmremote(void) *cp = '\0'; for (i = 0; i < requests; i++) { n = snprintf(cp, sizeof(buf) - (cp - buf), "%d ", requ[i]); - if (n == -1 || n >= sizeof(buf) - (cp - buf)) + if (n < 0 || n >= sizeof(buf) - (cp - buf)) goto bad; cp += n; } diff --git a/usr.sbin/lpr/common_source/startdaemon.c b/usr.sbin/lpr/common_source/startdaemon.c index aec300c4910..cb2551d9518 100644 --- a/usr.sbin/lpr/common_source/startdaemon.c +++ b/usr.sbin/lpr/common_source/startdaemon.c @@ -1,4 +1,4 @@ -/* $OpenBSD: startdaemon.c,v 1.17 2015/10/27 15:23:28 millert Exp $ */ +/* $OpenBSD: startdaemon.c,v 1.18 2019/07/03 03:24:03 deraadt Exp $ */ /* $NetBSD: startdaemon.c,v 1.10 1998/07/18 05:04:39 lukem Exp $ */ /* @@ -82,8 +82,8 @@ startdaemon(char *printer) } PRIV_END; siginterrupt(SIGINT, 0); - if ((n = snprintf(buf, sizeof(buf), "\1%s\n", printer)) >= sizeof(buf) || - n == -1) { + if ((n = snprintf(buf, sizeof(buf), "\1%s\n", printer)) < 0 || + n >= sizeof(buf)) { close(s); return (0); } diff --git a/usr.sbin/lpr/lpd/printjob.c b/usr.sbin/lpr/lpd/printjob.c index ff9428359f1..49c31626e64 100644 --- a/usr.sbin/lpr/lpd/printjob.c +++ b/usr.sbin/lpr/lpd/printjob.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printjob.c,v 1.60 2018/04/26 12:42:51 guenther Exp $ */ +/* $OpenBSD: printjob.c,v 1.61 2019/07/03 03:24:03 deraadt Exp $ */ /* $NetBSD: printjob.c,v 1.31 2002/01/21 14:42:30 wiz Exp $ */ /* @@ -187,8 +187,8 @@ printjob(void) * write process id for others to know */ pid = getpid(); - if ((pidoff = i = snprintf(line, sizeof(line), "%d\n", pid)) >= - sizeof(line) || pidoff == -1) { + if ((pidoff = i = snprintf(line, sizeof(line), "%d\n", pid)) < 0 || + i >= sizeof(line)) { syslog(LOG_ERR, "impossibly large pid: %u", pid); exit(1); } @@ -230,8 +230,8 @@ again: fino = (ino_t)-1; (void)lseek(lfd, pidoff, SEEK_SET); - if ((i = snprintf(line, sizeof(line), "%s\n", q->q_name)) >= - sizeof(line) || i == -1) + if ((i = snprintf(line, sizeof(line), "%s\n", q->q_name)) < 0 || + i >= sizeof(line)) i = sizeof(line) - 1; /* can't happen */ if (write(lfd, line, i) != i) syslog(LOG_ERR, "%s: %s: %m", printer, LO); @@ -913,7 +913,7 @@ sendfile(int type, char *file) if (f == -1) return(ERROR); if ((amt = snprintf(buf, sizeof(buf), "%c%lld %s\n", type, - (long long)stb.st_size, file)) >= sizeof(buf) || amt == -1) + (long long)stb.st_size, file)) < 0 || amt >= sizeof(buf)) return (ACCESS); /* XXX hack */ for (i = 0; ; i++) { if (write(pfd, buf, amt) != amt || @@ -1483,8 +1483,8 @@ openrem(void) resp = -1; pfd = getport(RM, 0); if (pfd >= 0) { - if ((n = snprintf(line, sizeof(line), "\2%s\n", RP)) >= - sizeof(line) || n == -1) + if ((n = snprintf(line, sizeof(line), "\2%s\n", RP)) < 0 || + n >= sizeof(line)) n = sizeof(line) - 1; if (write(pfd, line, n) == n && (resp = response()) == '\0') @@ -1600,7 +1600,7 @@ pstatus(const char *msg, ...) ftruncate(fd, 0); len = vsnprintf(buf, sizeof(buf), msg, ap); va_end(ap); - if (len == -1) { + if (len < 0) { (void)close(fd); return; } diff --git a/usr.sbin/radiusd/util.c b/usr.sbin/radiusd/util.c index 4c5b7bb1361..068bf8f0f5a 100644 --- a/usr.sbin/radiusd/util.c +++ b/usr.sbin/radiusd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.2 2015/08/27 01:02:35 yasuoka Exp $ */ +/* $OpenBSD: util.c,v 1.3 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2013 Internet Initiative Japan Inc. @@ -101,7 +101,7 @@ addrport_tostring(struct sockaddr *sa, socklen_t salen, char *buf, size_t lbuf) return "error"; } - if (ret == -1 || ret >= (int)lbuf) + if (ret < 0 || ret >= (int)lbuf) return "(error)"; return (buf); } diff --git a/usr.sbin/smtpd/envelope.c b/usr.sbin/smtpd/envelope.c index cd247a82c08..8e68a19f927 100644 --- a/usr.sbin/smtpd/envelope.c +++ b/usr.sbin/smtpd/envelope.c @@ -1,4 +1,4 @@ -/* $OpenBSD: envelope.c,v 1.42 2018/12/30 23:09:58 guenther Exp $ */ +/* $OpenBSD: envelope.c,v 1.43 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2013 Eric Faurot <eric@openbsd.org> @@ -59,7 +59,7 @@ envelope_set_errormsg(struct envelope *e, char *fmt, ...) va_end(ap); /* this should not happen */ - if (ret == -1) + if (ret < 0) err(1, "vsnprintf"); if ((size_t)ret >= sizeof(e->errorline)) @@ -748,7 +748,7 @@ envelope_ascii_dump(const struct envelope *ep, char **dest, size_t *len, return; l = snprintf(*dest, *len, "%s: %s\n", field, buf); - if (l == -1 || (size_t) l >= *len) + if (l < 0 || (size_t) l >= *len) goto err; *dest += l; *len -= l; diff --git a/usr.sbin/smtpd/mail.maildir.c b/usr.sbin/smtpd/mail.maildir.c index cc9d5429aa1..a4956f1ba19 100644 --- a/usr.sbin/smtpd/mail.maildir.c +++ b/usr.sbin/smtpd/mail.maildir.c @@ -99,7 +99,7 @@ maildir_mkdirs(const char *dirname) for (i = 0; i < nitems(subdirs); ++i) { ret = snprintf(pathname, sizeof pathname, "%s/%s", dirname, subdirs[i]); - if (ret == -1 || (size_t)ret >= sizeof pathname) + if (ret < 0 || (size_t)ret >= sizeof pathname) errc(1, ENAMETOOLONG, "%s/%s", dirname, subdirs[i]); if (mkdir(pathname, 0700) == -1 && errno != EEXIST) err(1, NULL); @@ -137,7 +137,7 @@ maildir_engine(const char *dirname, int junk) if ((home = getenv("HOME")) == NULL) err(1, NULL); ret = snprintf(rootpath, sizeof rootpath, "%s/Maildir", home); - if (ret == -1 || (size_t)ret >= sizeof rootpath) + if (ret < 0 || (size_t)ret >= sizeof rootpath) errc(1, ENAMETOOLONG, "%s/Maildir", home); dirname = rootpath; } @@ -146,7 +146,7 @@ maildir_engine(const char *dirname, int junk) if (junk) { /* create Junk subdirectory */ ret = snprintf(junkpath, sizeof junkpath, "%s/.Junk", dirname); - if (ret == -1 || (size_t)ret >= sizeof junkpath) + if (ret < 0 || (size_t)ret >= sizeof junkpath) errc(1, ENAMETOOLONG, "%s/.Junk", dirname); maildir_mkdirs(junkpath); } @@ -156,7 +156,7 @@ maildir_engine(const char *dirname, int junk) subdir[0]) { ret = snprintf(extpath, sizeof extpath, "%s/.%s", dirname, subdir); - if (ret == -1 || (size_t)ret >= sizeof extpath) + if (ret < 0 || (size_t)ret >= sizeof extpath) errc(1, ENAMETOOLONG, "%s/.%s", dirname, subdir); if (stat(extpath, &sb) != -1) { diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c index 67880cb0741..429fc5b610e 100644 --- a/usr.sbin/smtpd/smtp_session.c +++ b/usr.sbin/smtpd/smtp_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_session.c,v 1.394 2019/06/28 13:32:51 deraadt Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.395 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -2046,7 +2046,7 @@ smtp_reply(struct smtp_session *s, char *fmt, ...) va_start(ap, fmt); n = vsnprintf(buf, sizeof buf, fmt, ap); va_end(ap); - if (n == -1 || n >= LINE_MAX) + if (n < 0 || n >= LINE_MAX) fatalx("smtp_reply: line too long"); if (n < 4) fatalx("smtp_reply: response too short"); diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index b1d95aac0fe..30fea943cae 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.141 2019/06/28 13:32:51 deraadt Exp $ */ +/* $OpenBSD: util.c,v 1.142 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -176,7 +176,7 @@ bsnprintf(char *str, size_t size, const char *format, ...) va_start(ap, format); ret = vsnprintf(str, size, format, ap); va_end(ap); - if (ret == -1 || ret >= (int)size) + if (ret < 0 || ret >= (int)size) return 0; return 1; diff --git a/usr.sbin/tcpdump/print-bgp.c b/usr.sbin/tcpdump/print-bgp.c index 96bfd6d7a09..8a0f1699ba1 100644 --- a/usr.sbin/tcpdump/print-bgp.c +++ b/usr.sbin/tcpdump/print-bgp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-bgp.c,v 1.28 2019/05/11 13:13:47 claudio Exp $ */ +/* $OpenBSD: print-bgp.c,v 1.29 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (C) 1999 WIDE Project. @@ -384,7 +384,7 @@ decode_prefix4(const u_char *pd, char *buf, u_int buflen) ((0xff00 >> (plen % 8)) & 0xff); } n = snprintf(buf, buflen, "%s/%u", getname((u_char *)&addr), plen); - if (n == -1 || n >= buflen) + if (n < 0 || n >= buflen) return -1; return 1 + (plen + 7) / 8; @@ -414,7 +414,7 @@ decode_prefix6(const u_char *pd, char *buf, u_int buflen) } n = snprintf(buf, buflen, "%s/%u", getname6((u_char *)&addr), plen); - if (n == -1 || n >= buflen) + if (n < 0 || n >= buflen) return -1; return 1 + (plen + 7) / 8; diff --git a/usr.sbin/tftpd/tftpd.c b/usr.sbin/tftpd/tftpd.c index 5dd3533a2cd..4c0316d6463 100644 --- a/usr.sbin/tftpd/tftpd.c +++ b/usr.sbin/tftpd/tftpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tftpd.c,v 1.42 2019/06/28 13:32:51 deraadt Exp $ */ +/* $OpenBSD: tftpd.c,v 1.43 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 2012 David Gwynne <dlg@uq.edu.au> @@ -991,7 +991,7 @@ validate_access(struct tftp_client *client, const char *requested) */ ret = snprintf(rewritten, sizeof(rewritten), "%s/%s", getip(&client->ss), requested); - if (ret == -1 || ret >= sizeof(rewritten)) + if (ret < 0 || ret >= sizeof(rewritten)) return (ENAMETOOLONG + 100); filename = rewritten; } else { @@ -1502,7 +1502,7 @@ oack(struct tftp_client *client) n = snprintf(bp, size, "%s%c%lld", opt_names[i], '\0', options[i].o_reply); - if (n == -1 || n >= size) { + if (n < 0 || n >= size) { lwarnx("oack: no buffer space"); goto error; } diff --git a/usr.sbin/user/user.c b/usr.sbin/user/user.c index 2e39803df59..03de2b5e0bb 100644 --- a/usr.sbin/user/user.c +++ b/usr.sbin/user/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.126 2019/06/28 13:32:51 deraadt Exp $ */ +/* $OpenBSD: user.c,v 1.127 2019/07/03 03:24:03 deraadt Exp $ */ /* $NetBSD: user.c,v 1.69 2003/04/14 17:40:07 agc Exp $ */ /* @@ -1165,7 +1165,7 @@ adduser(char *login_name, user_t *up) if (yp) { /* put back the + line */ cc = snprintf(buf, sizeof(buf), "+:*::::::::\n"); - if (cc == -1 || cc >= sizeof(buf)) { + if (cc < 0 || cc >= sizeof(buf)) { close(ptmpfd); pw_abort(); errx(EXIT_FAILURE, "can't add `%s', line too long", buf); diff --git a/usr.sbin/ypserv/ypserv/ypserv_db.c b/usr.sbin/ypserv/ypserv/ypserv_db.c index 9b05da17a6e..f2caeca5204 100644 --- a/usr.sbin/ypserv/ypserv/ypserv_db.c +++ b/usr.sbin/ypserv/ypserv/ypserv_db.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypserv_db.c,v 1.30 2015/12/08 07:16:33 mmcc Exp $ */ +/* $OpenBSD: ypserv_db.c,v 1.31 2019/07/03 03:24:03 deraadt Exp $ */ /* * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se> @@ -422,7 +422,7 @@ lookup_host(int nametable, int host_lookup, DBM *db, char *keystr, } len = snprintf(val, sizeof(val), "%s %s", keystr, host->h_name); - if (len == (size_t)-1 || len >= sizeof(val)) + if (len < 0 || len >= sizeof(val)) return(YP_YPERR); v = val + len; while ((ptr = *(host->h_aliases)) != NULL) { |