aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-05-25 16:02:37 +0200
committerDuncaen <mail@duncano.de>2017-05-25 16:02:37 +0200
commit00bda52d272cd76e1e2a50d3b2131dbd1acabf1f (patch)
tree185d28383f14bd852d4130a0cc1b71c0075af28e
parent3d10a78d84cd6497ab671465e23e5b7de8b938f2 (diff)
downloadlobase-00bda52d272cd76e1e2a50d3b2131dbd1acabf1f.tar.gz
lib/liboutil: update
-rw-r--r--lib/liboutil/fmt_scaled.c25
-rw-r--r--lib/liboutil/imsg-buffer.c6
-rw-r--r--lib/liboutil/imsg.c16
-rw-r--r--lib/liboutil/logwtmp.c4
-rw-r--r--lib/liboutil/pkcs5_pbkdf2.c5
-rw-r--r--lib/liboutil/readlabel.c8
-rw-r--r--lib/liboutil/uucplock.c29
7 files changed, 58 insertions, 35 deletions
diff --git a/lib/liboutil/fmt_scaled.c b/lib/liboutil/fmt_scaled.c
index eecbde7..7a4dee2 100644
--- a/lib/liboutil/fmt_scaled.c
+++ b/lib/liboutil/fmt_scaled.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmt_scaled.c,v 1.12 2013/11/29 19:00:51 deraadt Exp $ */
+/* $OpenBSD: fmt_scaled.c,v 1.16 2017/03/16 02:40:46 dtucker Exp $ */
/*
* Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved.
@@ -121,14 +121,30 @@ scan_scaled(char *scaled, long long *result)
/* ignore extra fractional digits */
continue;
fract_digits++; /* for later scaling */
+ if (fpart > LLONG_MAX / 10) {
+ errno = ERANGE;
+ return -1;
+ }
fpart *= 10;
+ if (i > LLONG_MAX - fpart) {
+ errno = ERANGE;
+ return -1;
+ }
fpart += i;
} else { /* normal digit */
if (++ndigits >= MAX_DIGITS) {
errno = ERANGE;
return -1;
}
+ if (whole > LLONG_MAX / 10) {
+ errno = ERANGE;
+ return -1;
+ }
whole *= 10;
+ if (i > LLONG_MAX - whole) {
+ errno = ERANGE;
+ return -1;
+ }
whole += i;
}
}
@@ -158,6 +174,13 @@ scan_scaled(char *scaled, long long *result)
}
scale_fact = scale_factors[i];
+ /* check for overflow and underflow after scaling */
+ if (whole > LLONG_MAX / scale_fact ||
+ whole < LLONG_MIN / scale_fact) {
+ errno = ERANGE;
+ return -1;
+ }
+
/* scale whole part */
whole *= scale_fact;
diff --git a/lib/liboutil/imsg-buffer.c b/lib/liboutil/imsg-buffer.c
index 58c6655..821cb95 100644
--- a/lib/liboutil/imsg-buffer.c
+++ b/lib/liboutil/imsg-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg-buffer.c,v 1.8 2015/12/29 18:05:01 benno Exp $ */
+/* $OpenBSD: imsg-buffer.c,v 1.10 2017/04/11 09:57:19 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -78,7 +78,7 @@ ibuf_realloc(struct ibuf *buf, size_t len)
return (-1);
}
- b = realloc(buf->buf, buf->wpos + len);
+ b = recallocarray(buf->buf, buf->size, buf->wpos + len, 1);
if (b == NULL)
return (-1);
buf->buf = b;
@@ -182,7 +182,7 @@ ibuf_free(struct ibuf *buf)
{
if (buf == NULL)
return;
- free(buf->buf);
+ freezero(buf->buf, buf->size);
free(buf);
}
diff --git a/lib/liboutil/imsg.c b/lib/liboutil/imsg.c
index 9047997..c40041b 100644
--- a/lib/liboutil/imsg.c
+++ b/lib/liboutil/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.13 2015/12/09 11:54:12 tb Exp $ */
+/* $OpenBSD: imsg.c,v 1.15 2017/04/11 09:57:19 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -163,8 +163,8 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
}
int
-imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
- pid_t pid, int fd, const void *data, u_int16_t datalen)
+imsg_compose(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
+ int fd, const void *data, uint16_t datalen)
{
struct ibuf *wbuf;
@@ -182,8 +182,8 @@ imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
}
int
-imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
- pid_t pid, int fd, const struct iovec *iov, int iovcnt)
+imsg_composev(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
+ int fd, const struct iovec *iov, int iovcnt)
{
struct ibuf *wbuf;
int i, datalen = 0;
@@ -207,8 +207,8 @@ imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
/* ARGSUSED */
struct ibuf *
-imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid,
- pid_t pid, u_int16_t datalen)
+imsg_create(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
+ uint16_t datalen)
{
struct ibuf *wbuf;
struct imsg_hdr hdr;
@@ -263,7 +263,7 @@ imsg_close(struct imsgbuf *ibuf, struct ibuf *msg)
void
imsg_free(struct imsg *imsg)
{
- free(imsg->data);
+ freezero(imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE);
}
int
diff --git a/lib/liboutil/logwtmp.c b/lib/liboutil/logwtmp.c
index 0919000..f2759b3 100644
--- a/lib/liboutil/logwtmp.c
+++ b/lib/liboutil/logwtmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: logwtmp.c,v 1.9 2005/08/02 21:46:23 espie Exp $ */
+/* $OpenBSD: logwtmp.c,v 1.10 2016/08/30 14:44:45 guenther Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
@@ -46,7 +46,7 @@ logwtmp(const char *line, const char *name, const char *host)
struct utmp ut;
int fd;
- if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
+ if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND|O_CLOEXEC)) < 0)
return;
if (fstat(fd, &buf) == 0) {
(void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));
diff --git a/lib/liboutil/pkcs5_pbkdf2.c b/lib/liboutil/pkcs5_pbkdf2.c
index 789a712..83d31a4 100644
--- a/lib/liboutil/pkcs5_pbkdf2.c
+++ b/lib/liboutil/pkcs5_pbkdf2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pkcs5_pbkdf2.c,v 1.9 2015/02/05 12:59:57 millert Exp $ */
+/* $OpenBSD: pkcs5_pbkdf2.c,v 1.10 2017/04/18 04:06:21 deraadt Exp $ */
/*-
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr>
@@ -112,8 +112,7 @@ pkcs5_pbkdf2(const char *pass, size_t pass_len, const uint8_t *salt,
key += r;
key_len -= r;
};
- explicit_bzero(asalt, salt_len + 4);
- free(asalt);
+ freezero(asalt, salt_len + 4);
explicit_bzero(d1, sizeof(d1));
explicit_bzero(d2, sizeof(d2));
explicit_bzero(obuf, sizeof(obuf));
diff --git a/lib/liboutil/readlabel.c b/lib/liboutil/readlabel.c
index e2cee31..d53820e 100644
--- a/lib/liboutil/readlabel.c
+++ b/lib/liboutil/readlabel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: readlabel.c,v 1.13 2015/01/16 16:48:52 deraadt Exp $ */
+/* $OpenBSD: readlabel.c,v 1.14 2016/08/30 14:44:45 guenther Exp $ */
/*
* Copyright (c) 1996, Jason Downs. All rights reserved.
@@ -59,7 +59,7 @@ readlabelfs(char *device, int verbose)
/* Perform disk mapping if device is given as a DUID. */
if (isduid(device, 0)) {
- if ((fd = open("/dev/diskmap", O_RDONLY)) != -1) {
+ if ((fd = open("/dev/diskmap", O_RDONLY|O_CLOEXEC)) != -1) {
bzero(&dm, sizeof(struct dk_diskmap));
strlcpy(rpath, device, sizeof(rpath));
part = rpath[strlen(rpath) - 1];
@@ -105,12 +105,12 @@ readlabelfs(char *device, int verbose)
}
/* If rpath doesn't exist, change that partition back. */
- fd = open(rpath, O_RDONLY);
+ fd = open(rpath, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
if (errno == ENOENT) {
rpath[strlen(rpath) - 1] = part;
- fd = open(rpath, O_RDONLY);
+ fd = open(rpath, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
if (verbose)
warn("%s", rpath);
diff --git a/lib/liboutil/uucplock.c b/lib/liboutil/uucplock.c
index 59f8a27..0956ec0 100644
--- a/lib/liboutil/uucplock.c
+++ b/lib/liboutil/uucplock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uucplock.c,v 1.17 2015/11/11 01:12:09 deraadt Exp $ */
+/* $OpenBSD: uucplock.c,v 1.19 2016/08/30 14:52:09 guenther Exp $ */
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
@@ -71,7 +71,8 @@ uu_lock(const char *ttyname)
(long)pid);
(void)snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT,
ttyname);
- if ((tmpfd = open(lcktmpname, O_CREAT | O_TRUNC | O_WRONLY, 0664)) < 0)
+ tmpfd = open(lcktmpname, O_CREAT|O_TRUNC|O_WRONLY|O_CLOEXEC, 0664);
+ if (tmpfd < 0)
GORET(0, UU_LOCK_CREAT_ERR);
for (i = 0; i < MAXTRIES; i++) {
@@ -83,7 +84,7 @@ uu_lock(const char *ttyname)
* check to see if the process holding the lock
* still exists
*/
- if ((fd = open(lckname, O_RDONLY)) < 0)
+ if ((fd = open(lckname, O_RDONLY | O_CLOEXEC)) < 0)
GORET(1, UU_LOCK_OPEN_ERR);
if ((pid_old = get_pid(fd, &err)) == -1)
@@ -127,7 +128,7 @@ uu_lock_txfr(const char *ttyname, pid_t pid)
snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, ttyname);
- if ((fd = open(lckname, O_RDWR)) < 0)
+ if ((fd = open(lckname, O_RDWR | O_CLOEXEC)) < 0)
return UU_LOCK_OWNER_ERR;
if (get_pid(fd, &err) != getpid())
ret = UU_LOCK_OWNER_ERR;
@@ -153,7 +154,7 @@ const char *
uu_lockerr(int uu_lockresult)
{
static char errbuf[128];
- char *fmt;
+ const char *err;
switch (uu_lockresult) {
case UU_LOCK_INUSE:
@@ -161,32 +162,32 @@ uu_lockerr(int uu_lockresult)
case UU_LOCK_OK:
return "";
case UU_LOCK_OPEN_ERR:
- fmt = "open error: %s";
+ err = "open error";
break;
case UU_LOCK_READ_ERR:
- fmt = "read error: %s";
+ err = "read error";
break;
case UU_LOCK_CREAT_ERR:
- fmt = "creat error: %s";
+ err = "creat error";
break;
case UU_LOCK_WRITE_ERR:
- fmt = "write error: %s";
+ err = "write error";
break;
case UU_LOCK_LINK_ERR:
- fmt = "link error: %s";
+ err = "link error";
break;
case UU_LOCK_TRY_ERR:
- fmt = "too many tries: %s";
+ err = "too many tries";
break;
case UU_LOCK_OWNER_ERR:
- fmt = "not locking process: %s";
+ err = "not locking process";
break;
default:
- fmt = "undefined error: %s";
+ err = "undefined error";
break;
}
- (void)snprintf(errbuf, sizeof(errbuf), fmt, strerror(errno));
+ (void)snprintf(errbuf, sizeof(errbuf), "%s: %s", err, strerror(errno));
return errbuf;
}