ITS#4589 fix slap_compose_sync_cookie

This commit is contained in:
Howard Chu 2006-06-15 23:54:51 +00:00
parent a5b520477c
commit decba67ee9

View File

@ -38,24 +38,29 @@ slap_compose_sync_cookie(
int rid ) int rid )
{ {
char cookiestr[ LDAP_LUTIL_CSNSTR_BUFSIZE + 20 ]; char cookiestr[ LDAP_LUTIL_CSNSTR_BUFSIZE + 20 ];
int len;
if ( BER_BVISNULL( csn )) { if ( BER_BVISNULL( csn )) {
if ( rid == -1 ) { if ( rid == -1 ) {
cookiestr[0] = '\0'; cookiestr[0] = '\0';
len = 0;
} else { } else {
snprintf( cookiestr, LDAP_LUTIL_CSNSTR_BUFSIZE + 20, len = snprintf( cookiestr, LDAP_LUTIL_CSNSTR_BUFSIZE + 20,
"rid=%03d", rid ); "rid=%03d", rid );
} }
} else { } else {
if ( rid == -1 ) { char *end = cookiestr + sizeof(cookiestr);
snprintf( cookiestr, LDAP_LUTIL_CSNSTR_BUFSIZE + 20, char *ptr = lutil_strcopy( cookiestr, "csn=" );
"csn=%s", csn->bv_val ); len = csn->bv_len;
} else { if ( ptr + len >= end )
snprintf( cookiestr, LDAP_LUTIL_CSNSTR_BUFSIZE + 20, len = end - ptr;
"csn=%s,rid=%03d", csn->bv_val, rid ); ptr = lutil_strncopy( ptr, csn->bv_val, len );
if ( rid != -1 && ptr < end - STRLENOF(",rid=xxx") ) {
ptr += sprintf( ptr, ",rid=%03d", rid );
} }
len = ptr - cookiestr;
} }
ber_str2bv_x( cookiestr, strlen(cookiestr), 1, cookie, ber_str2bv_x( cookiestr, len, 1, cookie,
op ? op->o_tmpmemctx : NULL ); op ? op->o_tmpmemctx : NULL );
} }