mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-02-03 20:40:05 -05:00
ITS#10438 liblber: check for realloc failure in ber_bvreplace_x()
This commit is contained in:
parent
28546ce6b5
commit
0e893fd788
1 changed files with 14 additions and 3 deletions
|
|
@ -705,11 +705,22 @@ ber_bvreplace_x( struct berval *dst, LDAP_CONST struct berval *src, void *ctx )
|
||||||
assert( !BER_BVISNULL( src ) );
|
assert( !BER_BVISNULL( src ) );
|
||||||
|
|
||||||
if ( BER_BVISNULL( dst ) || dst->bv_len < src->bv_len ) {
|
if ( BER_BVISNULL( dst ) || dst->bv_len < src->bv_len ) {
|
||||||
dst->bv_val = ber_memrealloc_x( dst->bv_val, src->bv_len + 1, ctx );
|
char *ptr = ber_memrealloc_x( dst->bv_val, src->bv_len + 1, ctx );
|
||||||
|
if ( ptr != NULL ) {
|
||||||
|
dst->bv_val = ptr;
|
||||||
|
dst->bv_len = src->bv_len;
|
||||||
|
}
|
||||||
|
/* if realloc failed, dst is left unchanged
|
||||||
|
* and the value copied into it will be truncated.
|
||||||
|
* callers never check this function's return value.
|
||||||
|
*/
|
||||||
|
} else {
|
||||||
|
dst->bv_len = src->bv_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
AC_MEMCPY( dst->bv_val, src->bv_val, src->bv_len + 1 );
|
if ( dst->bv_val != NULL ) {
|
||||||
dst->bv_len = src->bv_len;
|
AC_MEMCPY( dst->bv_val, src->bv_val, dst->bv_len + 1 );
|
||||||
|
}
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue