summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2020-09-03 17:01:16 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2020-09-03 17:01:16 +0000
commit53829ce0edb94697355c3f1a56b96050ee4e9a40 (patch)
tree33aa25e9381db02da593022525f0aada310b0168 /lib
parent04e4a5c44b7adb88788d2c4c27699e8ec3445764 (diff)
Make sure ober_read_elements sets errno on every case where NULL is
returned. OK deraadt@ tb@
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/ber.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/libutil/ber.c b/lib/libutil/ber.c
index 0e1914c5faa..d7cc863eaeb 100644
--- a/lib/libutil/ber.c
+++ b/lib/libutil/ber.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ber.c,v 1.15 2019/10/24 12:39:26 tb Exp $ */
+/* $OpenBSD: ber.c,v 1.16 2020/09/03 17:01:15 martijn Exp $ */
/*
* Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
@@ -1266,8 +1266,10 @@ ober_read_element(struct ber *ber, struct ber_element *elm)
/* smallest number of contents octets only */
if ((i == 1 && last == 0 && (c & 0x80) == 0) ||
- (i == 1 && last == 0xff && (c & 0x80) != 0))
+ (i == 1 && last == 0xff && (c & 0x80) != 0)) {
+ errno = EINVAL;
return -1;
+ }
val <<= 8;
val |= c;
@@ -1299,8 +1301,10 @@ ober_read_element(struct ber *ber, struct ber_element *elm)
((u_char *)elm->be_val)[len] = '\0';
break;
case BER_TYPE_NULL: /* no payload */
- if (len != 0)
+ if (len != 0) {
+ errno = EINVAL;
return -1;
+ }
break;
case BER_TYPE_SEQUENCE:
case BER_TYPE_SET:
@@ -1346,8 +1350,10 @@ ober_read(struct ber *ber, void *buf, size_t len)
{
size_t sz;
- if (ber->br_rbuf == NULL)
+ if (ber->br_rbuf == NULL) {
+ errno = ENOBUFS;
return -1;
+ }
sz = ber->br_rend - ber->br_rptr;
if (len > sz) {