]> git.sur5r.net Git - openldap/commitdiff
Add options for ber_get_stringbv() to omit NUL-terminator, to allow
authorHoward Chu <hyc@openldap.org>
Fri, 23 Mar 2007 15:27:38 +0000 (15:27 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 23 Mar 2007 15:27:38 +0000 (15:27 +0000)
non-destructive in-place parsing

include/lber.h
libraries/liblber/decode.c

index 630e62ab05a0be8995cd963191355244b8cbc5c3..9d05c4f5468e2b3ddc142ef698e7e26fadde3c44 100644 (file)
@@ -267,11 +267,14 @@ ber_get_stringb LDAP_P((
        char *buf,
        ber_len_t *len ));
 
+#define        LBER_BV_ALLOC   0x01    /* allocate/copy result, otherwise in-place */
+#define        LBER_BV_NOTERM  0x02    /* omit NUL-terminator if parsing in-place */
+
 LBER_F( ber_tag_t )
 ber_get_stringbv LDAP_P((
        BerElement *ber,
        struct berval *bv,
-       int alloc ));
+       int options ));
 
 LBER_F( ber_tag_t )
 ber_get_stringa LDAP_P((
index 2dbd85602c62a153be4e7587e2f0fdc1fbaa0b0e..3b8516e6ea235b9f5cdc974f20719ec141e349df 100644 (file)
@@ -471,7 +471,7 @@ nomem:
 }
 
 ber_tag_t
-ber_get_stringbv( BerElement *ber, struct berval *bv, int alloc )
+ber_get_stringbv( BerElement *ber, struct berval *bv, int option )
 {
        ber_tag_t       tag;
 
@@ -489,7 +489,7 @@ ber_get_stringbv( BerElement *ber, struct berval *bv, int alloc )
                return LBER_DEFAULT;
        }
 
-       if ( alloc ) {
+       if ( option & LBER_BV_ALLOC ) {
                bv->bv_val = (char *) ber_memalloc_x( bv->bv_len + 1,
                        ber->ber_memctx );
                if ( bv->bv_val == NULL ) {
@@ -508,13 +508,14 @@ ber_get_stringbv( BerElement *ber, struct berval *bv, int alloc )
                ber->ber_ptr += bv->bv_len;
        }
        ber->ber_tag = *(unsigned char *)ber->ber_ptr;
-       bv->bv_val[bv->bv_len] = '\0';
+       if ( !( option & LBER_BV_NOTERM ))
+               bv->bv_val[bv->bv_len] = '\0';
 
        return tag;
 }
 
 ber_tag_t
-ber_get_stringbv_null( BerElement *ber, struct berval *bv, int alloc )
+ber_get_stringbv_null( BerElement *ber, struct berval *bv, int option )
 {
        ber_tag_t       tag;
 
@@ -538,7 +539,7 @@ ber_get_stringbv_null( BerElement *ber, struct berval *bv, int alloc )
                return tag;
        }
 
-       if ( alloc ) {
+       if ( option & LBER_BV_ALLOC ) {
                bv->bv_val = (char *) ber_memalloc_x( bv->bv_len + 1,
                        ber->ber_memctx );
                if ( bv->bv_val == NULL ) {
@@ -557,7 +558,8 @@ ber_get_stringbv_null( BerElement *ber, struct berval *bv, int alloc )
                ber->ber_ptr += bv->bv_len;
        }
        ber->ber_tag = *(unsigned char *)ber->ber_ptr;
-       bv->bv_val[bv->bv_len] = '\0';
+       if ( !( option & LBER_BV_NOTERM ))
+               bv->bv_val[bv->bv_len] = '\0';
 
        return tag;
 }
@@ -570,7 +572,7 @@ ber_get_stringa( BerElement *ber, char **buf )
 
        assert( buf != NULL );
 
-       tag = ber_get_stringbv( ber, &bv, 1 );
+       tag = ber_get_stringbv( ber, &bv, LBER_BV_ALLOC );
        *buf = bv.bv_val;
 
        return tag;
@@ -584,7 +586,7 @@ ber_get_stringa_null( BerElement *ber, char **buf )
 
        assert( buf != NULL );
 
-       tag = ber_get_stringbv_null( ber, &bv, 1 );
+       tag = ber_get_stringbv_null( ber, &bv, LBER_BV_ALLOC );
        *buf = bv.bv_val;
 
        return tag;
@@ -604,7 +606,7 @@ ber_get_stringal( BerElement *ber, struct berval **bv )
                return LBER_DEFAULT;
        }
 
-       tag = ber_get_stringbv( ber, *bv, 1 );
+       tag = ber_get_stringbv( ber, *bv, LBER_BV_ALLOC );
        if ( tag == LBER_DEFAULT ) {
                LBER_FREE( *bv );
                *bv = NULL;
@@ -845,7 +847,7 @@ ber_scanf ( BerElement *ber,
 
                case 'o':       /* octet string in a supplied berval */
                        bval = va_arg( ap, struct berval * );
-                       rc = ber_get_stringbv( ber, bval, 1 );
+                       rc = ber_get_stringbv( ber, bval, LBER_BV_ALLOC );
                        break;
 
                case 'O':       /* octet string - allocate & include length */
@@ -874,7 +876,7 @@ ber_scanf ( BerElement *ber,
                        bgbvr cookie = { ChArray };
                        cookie.ber = ber;
                        cookie.res.c = va_arg( ap, char *** );
-                       cookie.alloc = 1;
+                       cookie.alloc = LBER_BV_ALLOC;
                        rc = ber_get_stringbvl( &cookie, NULL );
                        break;
                }
@@ -884,7 +886,7 @@ ber_scanf ( BerElement *ber,
                        bgbvr cookie = { BvVec };
                        cookie.ber = ber;
                        cookie.res.bv = va_arg( ap, struct berval *** );
-                       cookie.alloc = 1;
+                       cookie.alloc = LBER_BV_ALLOC;
                        rc = ber_get_stringbvl( &cookie, NULL );
                        break;
                }
@@ -894,7 +896,7 @@ ber_scanf ( BerElement *ber,
                        bgbvr cookie = { BvArray };
                        cookie.ber = ber;
                        cookie.res.ba = va_arg( ap, struct berval ** );
-                       cookie.alloc = 1;
+                       cookie.alloc = LBER_BV_ALLOC;
                        rc = ber_get_stringbvl( &cookie, NULL );
                        break;
                }