summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2019-07-03 03:24:05 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2019-07-03 03:24:05 +0000
commit75fca2aa3a35362ecff27f0c3041d3f511b51275 (patch)
treed0c647e96313c8d94edf3f50304b78ae1cf249c1 /lib
parentaef6c060ee15355c0490999de3c4679d7bb97e84 (diff)
snprintf/vsnprintf return < 0 on error, rather than -1.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/asr/asr_debug.c4
-rw-r--r--lib/libc/asr/getnameinfo.c4
-rw-r--r--lib/libc/asr/getnameinfo_async.c4
-rw-r--r--lib/libc/gen/getcap.c4
-rw-r--r--lib/libc/locale/setlocale.c4
-rw-r--r--lib/libc/net/inet_net_ntop.c4
-rw-r--r--lib/libc/rpc/clnt_perror.c18
-rw-r--r--lib/libc/time/asctime.c4
-rw-r--r--lib/libcrypto/objects/obj_dat.c6
-rw-r--r--lib/libcrypto/ts/ts_rsp_sign.c4
-rw-r--r--lib/libutil/uucplock.c16
11 files changed, 37 insertions, 35 deletions
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