version 1.127, 2009/08/12 20:13:50
|
version 1.128, 2009/10/28 22:00:27
|
Line 1
|
Line 1
|
/* decode.c - ber input decoding routines */ |
/* decode.c - ber input decoding routines */ |
/* $OpenLDAP: pkg/ldap/libraries/liblber/decode.c,v 1.126 2009/08/07 17:26:11 hallvard Exp $ */ |
/* $OpenLDAP: pkg/ldap/libraries/liblber/decode.c,v 1.127 2009/08/12 20:13:50 hallvard Exp $ */ |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
* |
* |
* Copyright 1998-2009 The OpenLDAP Foundation. |
* Copyright 1998-2009 The OpenLDAP Foundation. |
Line 345 enum bgbvc { ChArray, BvArray, BvVec, Bv
|
Line 345 enum bgbvc { ChArray, BvArray, BvVec, Bv
|
*/ |
*/ |
typedef struct bgbvr { |
typedef struct bgbvr { |
const enum bgbvc choice; |
const enum bgbvc choice; |
const int alloc; /* choice == BvOff ? 0 : LBER_ALLOC */ |
const int option; /* (ALLOC unless BvOff) | (STRING if ChArray) */ |
ber_len_t siz; /* input array element size, output count */ |
ber_len_t siz; /* input array element size, output count */ |
ber_len_t off; /* BvOff offset to the struct berval */ |
ber_len_t off; /* BvOff offset to the struct berval */ |
void *result; |
void *result; |
Line 418 ber_get_stringbvl( BerElement *ber, bgbv
|
Line 418 ber_get_stringbvl( BerElement *ber, bgbv
|
|
|
n = 0; |
n = 0; |
do { |
do { |
tag = ber_get_stringbv( ber, &bv, b->alloc ); |
tag = ber_get_stringbv( ber, &bv, b->option ); |
if ( tag == LBER_DEFAULT ) { |
if ( tag == LBER_DEFAULT ) { |
goto nomem; |
goto failed; |
} |
} |
|
|
/* store my result */ |
/* store my result */ |
Line 436 ber_get_stringbvl( BerElement *ber, bgbv
|
Line 436 ber_get_stringbvl( BerElement *ber, bgbv
|
ber->ber_memctx ); |
ber->ber_memctx ); |
if ( !bvp ) { |
if ( !bvp ) { |
ber_memfree_x( bv.bv_val, ber->ber_memctx ); |
ber_memfree_x( bv.bv_val, ber->ber_memctx ); |
goto nomem; |
goto failed; |
} |
} |
res.bv[n] = bvp; |
res.bv[n] = bvp; |
*bvp = bv; |
*bvp = bv; |
Line 449 ber_get_stringbvl( BerElement *ber, bgbv
|
Line 449 ber_get_stringbvl( BerElement *ber, bgbv
|
} while (++n < i); |
} while (++n < i); |
return tag; |
return tag; |
|
|
nomem: |
failed: |
if (b->choice != BvOff) { /* BvOff does not have b->alloc set */ |
if (b->choice != BvOff) { /* BvOff does not have LBER_BV_ALLOC set */ |
while (--n >= 0) { |
while (--n >= 0) { |
switch(b->choice) { |
switch(b->choice) { |
case ChArray: |
case ChArray: |
Line 480 ber_get_stringbv( BerElement *ber, struc
|
Line 480 ber_get_stringbv( BerElement *ber, struc
|
char *data; |
char *data; |
|
|
tag = ber_skip_element( ber, bv ); |
tag = ber_skip_element( ber, bv ); |
if ( tag == LBER_DEFAULT ) { |
if ( tag == LBER_DEFAULT || |
|
(( option & LBER_BV_STRING ) && memchr( bv->bv_val, 0, bv->bv_len ))) |
|
{ |
bv->bv_val = NULL; |
bv->bv_val = NULL; |
return tag; |
return LBER_DEFAULT; |
} |
} |
|
|
data = bv->bv_val; |
data = bv->bv_val; |
Line 516 ber_get_stringbv_null( BerElement *ber,
|
Line 518 ber_get_stringbv_null( BerElement *ber,
|
return tag; |
return tag; |
} |
} |
|
|
|
if (( option & LBER_BV_STRING ) && memchr( bv->bv_val, 0, bv->bv_len )) { |
|
bv->bv_val = NULL; |
|
return LBER_DEFAULT; |
|
} |
|
|
data = bv->bv_val; |
data = bv->bv_val; |
if ( option & LBER_BV_ALLOC ) { |
if ( option & LBER_BV_ALLOC ) { |
bv->bv_val = (char *) ber_memalloc_x( bv->bv_len + 1, |
bv->bv_val = (char *) ber_memalloc_x( bv->bv_len + 1, |
Line 541 ber_get_stringa( BerElement *ber, char *
|
Line 548 ber_get_stringa( BerElement *ber, char *
|
|
|
assert( buf != NULL ); |
assert( buf != NULL ); |
|
|
tag = ber_get_stringbv( ber, &bv, LBER_BV_ALLOC ); |
tag = ber_get_stringbv( ber, &bv, LBER_BV_ALLOC | LBER_BV_STRING ); |
*buf = bv.bv_val; |
*buf = bv.bv_val; |
|
|
return tag; |
return tag; |
Line 555 ber_get_stringa_null( BerElement *ber, c
|
Line 562 ber_get_stringa_null( BerElement *ber, c
|
|
|
assert( buf != NULL ); |
assert( buf != NULL ); |
|
|
tag = ber_get_stringbv_null( ber, &bv, LBER_BV_ALLOC ); |
tag = ber_get_stringbv_null( ber, &bv, LBER_BV_ALLOC | LBER_BV_STRING ); |
*buf = bv.bv_val; |
*buf = bv.bv_val; |
|
|
return tag; |
return tag; |
Line 608 ber_get_bitstringa(
|
Line 615 ber_get_bitstringa(
|
goto fail; |
goto fail; |
} |
} |
|
|
|
if ( memchr( data.bv_val, 0, data.bv_len )) { |
|
goto fail; |
|
} |
|
|
*buf = (char *) ber_memalloc_x( data.bv_len, ber->ber_memctx ); |
*buf = (char *) ber_memalloc_x( data.bv_len, ber->ber_memctx ); |
if ( *buf == NULL ) { |
if ( *buf == NULL ) { |
return LBER_DEFAULT; |
return LBER_DEFAULT; |
Line 811 ber_scanf ( BerElement *ber,
|
Line 822 ber_scanf ( BerElement *ber,
|
case 'v': /* sequence of strings */ |
case 'v': /* sequence of strings */ |
{ |
{ |
bgbvr cookie = { |
bgbvr cookie = { |
ChArray, LBER_BV_ALLOC, sizeof( char * ) |
ChArray, LBER_BV_ALLOC | LBER_BV_STRING, sizeof( char * ) |
}; |
}; |
rc = ber_get_stringbvl( ber, &cookie ); |
rc = ber_get_stringbvl( ber, &cookie ); |
*(va_arg( ap, char *** )) = cookie.result; |
*(va_arg( ap, char *** )) = cookie.result; |