ITS#10438 liblber: check for realloc failure in ber_bvreplace_x()

This commit is contained in:
Howard Chu 2026-02-02 16:49:07 +00:00
parent 28546ce6b5
commit 0e893fd788

View file

@ -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;
} }