version 1.72, 2002/01/03 02:11:14
|
version 1.73, 2002/01/03 02:30:55
|
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.71 2002/01/03 01:53:41 hyc Exp $ */ |
/* $OpenLDAP: pkg/ldap/libraries/liblber/decode.c,v 1.72 2002/01/03 02:11:14 hyc Exp $ */ |
/* |
/* |
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. |
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. |
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file |
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file |
Line 278 ber_get_stringb(
|
Line 278 ber_get_stringb(
|
return tag; |
return tag; |
} |
} |
|
|
|
/* Definitions for recursive get_string */ |
|
|
enum bgbvc { ChArray, BvArray, BvVec }; |
enum bgbvc { ChArray, BvArray, BvVec }; |
|
|
|
/* Use this single cookie for state, to keep actual |
|
* stack use to the absolute minimum. |
|
*/ |
typedef struct bgbvr { |
typedef struct bgbvr { |
BerElement *ber; |
BerElement *ber; |
enum bgbvc choice; |
enum bgbvc choice; |
Line 293 typedef struct bgbvr {
|
Line 298 typedef struct bgbvr {
|
} res; |
} res; |
} bgbvr; |
} bgbvr; |
|
|
|
/* Recursive get_string, for decoding a vector of strings. The number |
|
* of elements in the vector is limited only by available stack space. |
|
* Each invocation consumes 24 bytes of stack on a 32-bit machine. |
|
*/ |
ber_tag_t |
ber_tag_t |
ber_get_stringbvr( bgbvr *b, int n ) |
ber_get_stringbvr( bgbvr *b, int n ) |
{ |
{ |
Line 309 ber_get_stringbvr( bgbvr *b, int n )
|
Line 318 ber_get_stringbvr( bgbvr *b, int n )
|
*b->res.c = NULL; |
*b->res.c = NULL; |
return 0; |
return 0; |
} |
} |
/* do the allocation */ |
/* Allocate the result vector */ |
switch (b->choice) { |
switch (b->choice) { |
case ChArray: |
case ChArray: |
*b->res.c = LBER_MALLOC( (n+1) * sizeof( char * )); |
*b->res.c = LBER_MALLOC( (n+1) * sizeof( char * )); |
Line 324 ber_get_stringbvr( bgbvr *b, int n )
|
Line 333 ber_get_stringbvr( bgbvr *b, int n )
|
(*b->res.bv)[n] = NULL; |
(*b->res.bv)[n] = NULL; |
break; |
break; |
} |
} |
|
/* Did the malloc succeed? */ |
|
if ( *b->res.c == NULL ) |
|
return LBER_DEFAULT; |
return 0; |
return 0; |
} |
} |
|
|
|
/* Do all local allocs before the recursion. Then there |
|
* cannot possibly be any failures on the return trip. |
|
*/ |
if ( b->choice == BvVec ) |
if ( b->choice == BvVec ) |
bvp = LBER_MALLOC( sizeof( struct berval )); |
bvp = LBER_MALLOC( sizeof( struct berval )); |
|
|
Line 336 ber_get_stringbvr( bgbvr *b, int n )
|
Line 351 ber_get_stringbvr( bgbvr *b, int n )
|
} |
} |
|
|
b->tag = ber_get_stringbvr( b, n+1 ); |
b->tag = ber_get_stringbvr( b, n+1 ); |
|
|
if ( b->tag == 0 ) |
if ( b->tag == 0 ) |
{ |
{ |
/* store my result */ |
/* store my result */ |
Line 352 ber_get_stringbvr( bgbvr *b, int n )
|
Line 368 ber_get_stringbvr( bgbvr *b, int n )
|
break; |
break; |
} |
} |
} else { |
} else { |
|
/* Failure will propagate up and free in reverse |
|
* order, which is actually ideal. |
|
*/ |
if ( bvp ) LBER_FREE( bvp ); |
if ( bvp ) LBER_FREE( bvp ); |
LBER_FREE( bv.bv_val ); |
LBER_FREE( bv.bv_val ); |
} |
} |
Line 549 ber_next_element(
|
Line 568 ber_next_element(
|
} |
} |
|
|
/* Hopefully no one sends vectors with more elements than this */ |
/* Hopefully no one sends vectors with more elements than this */ |
|
/* Don't define this! ber_get_stringbvr works much much better! */ |
/* #define TMP_SLOTS 1024 */ |
/* #define TMP_SLOTS 1024 */ |
|
|
/* VARARGS */ |
/* VARARGS */ |