From 1b679b9b306484cbb0dd7005eff2ecf870a8f88d Mon Sep 17 00:00:00 2001 From: rob Date: Fri, 13 Jul 2018 08:30:10 +0000 Subject: [PATCH] Fix loop condition in ber.c. Discussed with claudio. ok claudio@, jca@ --- usr.bin/ldap/ber.c | 11 +++++------ usr.sbin/ldapd/ber.c | 11 +++++------ usr.sbin/snmpd/ber.c | 11 +++++------ usr.sbin/ypldap/ber.c | 11 +++++------ 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/usr.bin/ldap/ber.c b/usr.bin/ldap/ber.c index ffdafb263cb..47f0880407a 100644 --- a/usr.bin/ldap/ber.c +++ b/usr.bin/ldap/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.12 2018/07/09 09:21:26 jca Exp $ */ +/* $OpenBSD: ber.c,v 1.13 2018/07/13 08:30:10 rob Exp $ */ /* * Copyright (c) 2007, 2012 Reyk Floeter @@ -1032,13 +1032,12 @@ get_id(struct ber *b, unsigned long *tag, int *class, int *cstruct) return -1; t = (t << 7) | (u & ~BER_TAG_MORE); i++; + if (i > sizeof(unsigned long)) { + errno = ERANGE; + return -1; + } } while (u & BER_TAG_MORE); - if (i > sizeof(unsigned long)) { - errno = ERANGE; - return -1; - } - *tag = t; return i + 1; } diff --git a/usr.sbin/ldapd/ber.c b/usr.sbin/ldapd/ber.c index 65c952b1137..0b955b3271f 100644 --- a/usr.sbin/ldapd/ber.c +++ b/usr.sbin/ldapd/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.22 2018/07/09 09:21:26 jca Exp $ */ +/* $OpenBSD: ber.c,v 1.23 2018/07/13 08:30:10 rob Exp $ */ /* * Copyright (c) 2007, 2012 Reyk Floeter @@ -1032,13 +1032,12 @@ get_id(struct ber *b, unsigned long *tag, int *class, int *cstruct) return -1; t = (t << 7) | (u & ~BER_TAG_MORE); i++; + if (i > sizeof(unsigned long)) { + errno = ERANGE; + return -1; + } } while (u & BER_TAG_MORE); - if (i > sizeof(unsigned long)) { - errno = ERANGE; - return -1; - } - *tag = t; return i + 1; } diff --git a/usr.sbin/snmpd/ber.c b/usr.sbin/snmpd/ber.c index a760edd8fde..7a966e6679f 100644 --- a/usr.sbin/snmpd/ber.c +++ b/usr.sbin/snmpd/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.41 2018/07/09 09:21:26 jca Exp $ */ +/* $OpenBSD: ber.c,v 1.42 2018/07/13 08:30:10 rob Exp $ */ /* * Copyright (c) 2007, 2012 Reyk Floeter @@ -1032,13 +1032,12 @@ get_id(struct ber *b, unsigned long *tag, int *class, int *cstruct) return -1; t = (t << 7) | (u & ~BER_TAG_MORE); i++; + if (i > sizeof(unsigned long)) { + errno = ERANGE; + return -1; + } } while (u & BER_TAG_MORE); - if (i > sizeof(unsigned long)) { - errno = ERANGE; - return -1; - } - *tag = t; return i + 1; } diff --git a/usr.sbin/ypldap/ber.c b/usr.sbin/ypldap/ber.c index c2696f24e3c..fc714e0aa75 100644 --- a/usr.sbin/ypldap/ber.c +++ b/usr.sbin/ypldap/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.24 2018/07/09 09:21:26 jca Exp $ */ +/* $OpenBSD: ber.c,v 1.25 2018/07/13 08:30:10 rob Exp $ */ /* * Copyright (c) 2007, 2012 Reyk Floeter @@ -1032,13 +1032,12 @@ get_id(struct ber *b, unsigned long *tag, int *class, int *cstruct) return -1; t = (t << 7) | (u & ~BER_TAG_MORE); i++; + if (i > sizeof(unsigned long)) { + errno = ERANGE; + return -1; + } } while (u & BER_TAG_MORE); - if (i > sizeof(unsigned long)) { - errno = ERANGE; - return -1; - } - *tag = t; return i + 1; } -- 2.20.1