]> git.sur5r.net Git - openldap/blobdiff - libraries/liblber/decode.c
check for overflows
[openldap] / libraries / liblber / decode.c
index 3c2c780e3a2e05d0220900fbb065337564be4350..5238564ca8f6742b626a696dc8728bb58d13b312 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2007 The OpenLDAP Foundation.
+ * Copyright 1998-2008 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -69,7 +69,7 @@ ber_decode_oid( BerValue *in, BerValue *out )
                val |= der[i] & 0x7f;
                if ( !( der[i] & 0x80 )) {
                        if ( ptr == NULL ) {
-                               /* Initial "x.y": val=x*40+y, x<=2, y<40 if x=2 */
+                               /* Initial "x.y": val=x*40+y, x<=2, y<40 if x<2 */
                                ptr = out->bv_val;
                                val1 = (val < 80 ? val/40 : 2);
                                val -= val1*40;
@@ -419,7 +419,7 @@ ber_get_stringbvl( bgbvr *b, ber_len_t *rlen )
        case BvOff:
                *b->res.ba = ber_memalloc_x( (n+1) * b->siz, b->ber->ber_memctx );
                if ( *b->res.ba == NULL ) return LBER_DEFAULT;
-               ((struct berval *)((long)(*b->res.ba) + n*b->siz +
+               ((struct berval *)((char *)(*b->res.ba) + n*b->siz +
                        b->off))->bv_val = NULL;
                break;
        }
@@ -452,7 +452,7 @@ ber_get_stringbvl( bgbvr *b, ber_len_t *rlen )
                        *bvp = bv;
                        break;
                case BvOff:
-                       *(BerVarray)((long)(*b->res.ba)+n*b->siz+b->off) = bv;
+                       *(BerVarray)((char *)(*b->res.ba)+n*b->siz+b->off) = bv;
                        break;
                }
        }
@@ -780,9 +780,11 @@ ber_scanf ( BerElement *ber,
 
        fmt_reset = fmt;
 
-       ber_log_printf( LDAP_DEBUG_TRACE, ber->ber_debug,
-               "ber_scanf fmt (%s) ber:\n", fmt );
-       ber_log_dump( LDAP_DEBUG_BER, ber->ber_debug, ber, 1 );
+       if ( ber->ber_debug & (LDAP_DEBUG_TRACE|LDAP_DEBUG_BER)) {
+               ber_log_printf( LDAP_DEBUG_TRACE, ber->ber_debug,
+                       "ber_scanf fmt (%s) ber:\n", fmt );
+               ber_log_dump( LDAP_DEBUG_BER, ber->ber_debug, ber, 1 );
+       }
 
        for ( rc = 0; *fmt && rc != LBER_DEFAULT; fmt++ ) {
                /* When this is modified, remember to update