From: Pierangelo Masarati Date: Fri, 9 Aug 2002 13:51:35 +0000 (+0000) Subject: remove dependency from LDAP_FILT_MAXSIZ (and handle arbitrary size filters) X-Git-Tag: NO_SLAP_OP_BLOCKS~1254 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=85a74efc71e5c800ef7227ac033551ccd300e86f;p=openldap remove dependency from LDAP_FILT_MAXSIZ (and handle arbitrary size filters) --- diff --git a/servers/slapd/back-ldap/config.c b/servers/slapd/back-ldap/config.c index bcb209d935..42e44659bf 100644 --- a/servers/slapd/back-ldap/config.c +++ b/servers/slapd/back-ldap/config.c @@ -431,10 +431,40 @@ suffix_massage_config( * walk the filter looking for DN-valued attributes, * and only rewrite those that require rewriting */ - char vbuf[LDAP_FILT_MAXSIZ], rbuf[LDAP_FILT_MAXSIZ]; + char vbuf_[BUFSIZ], *vbuf = vbuf_, + rbuf_[BUFSIZ], *rbuf = rbuf_; + int len; + + len = snprintf( vbuf, sizeof( vbuf_ ), + "(.*)%s\\)(.*)", nvnc->bv_val ); + if ( len == -1 ) { + /* + * traditional behavior: snprintf returns -1 + * if buffer is insufficient + */ + return -1; + + } else if ( len >= sizeof( vbuf_ ) ) { + /* + * C99: snprintf returns the required size + */ + vbuf = ch_malloc( len + 1 ); + len = snprintf( vbuf, len, + "(.*)%s\\)(.*)", nvnc->bv_val ); + assert( len > 0 ); + } + + len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2", + nrnc->bv_val ); + if ( len == -1 ) { + return -1; - snprintf( vbuf, sizeof( vbuf ), "(.*)%s\\)(.*)", nvnc->bv_val ); - snprintf( rbuf, sizeof( rbuf ), "%%1%s)%%2", nrnc->bv_val ); + } else if ( len >= sizeof( rbuf_ ) ) { + rbuf = ch_malloc( len + 1 ); + len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2", + nrnc->bv_val ); + assert( len > 0 ); + } rargv[ 0 ] = "rewriteRule"; rargv[ 1 ] = vbuf; @@ -442,6 +472,14 @@ suffix_massage_config( rargv[ 3 ] = ":"; rargv[ 4 ] = NULL; rewrite_parse( info, "", ++line, 4, rargv ); + + if ( vbuf != vbuf_ ) { + ch_free( vbuf ); + } + + if ( rbuf != rbuf_ ) { + ch_free( rbuf ); + } } #endif /* rewrite filters */