- Fix a buffer overflow in highlighter. [1]

- Apply upstream patches to plug a memory leak, etc.
- Move CLuceneConfig.cmake to DATADIR as other ports do.
- Fix several problems found by Clang and make it build cleanly.

Submitted by:	Kishore Ramareddy (kishore at niksun dot com)
		(initial version) [1]
This commit is contained in:
Jung-uk Kim 2013-03-28 00:18:41 +00:00
parent 95a10dae4d
commit 31a4a592a1
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=315423
12 changed files with 214 additions and 7 deletions

View file

@ -3,6 +3,7 @@
PORTNAME= clucene
PORTVERSION= 2.3.3.4
PORTREVISION= 1
CATEGORIES= textproc
MASTER_SITES= SF/${PORTNAME}/${PORTNAME}-core-unstable/2.3
DISTNAME= ${PORTNAME}-core-${PORTVERSION}
@ -22,4 +23,8 @@ USE_LDCONFIG= yes
CMAKE_ARGS= -DBUILD_CONTRIBS_LIB=ON
CXXFLAGS+= -D__LONG_LONG_SUPPORTED
post-patch:
@${REINPLACE_CMD} -e 's|%%DATADIR%%|${DATADIR_REL}|' \
${WRKSRC}/src/core/CMakeLists.txt
.include <bsd.port.mk>

View file

@ -1,5 +1,40 @@
--- CMakeLists.txt.orig 2011-03-16 20:21:07.000000000 -0400
+++ CMakeLists.txt 2012-08-07 16:27:55.000000000 -0400
+++ CMakeLists.txt 2013-03-27 15:33:37.000000000 -0400
@@ -62,14 +62,14 @@
OFF)
SET(ENABLE_ANSI_MODE OFF)
-IF(CMAKE_COMPILER_IS_GNUCXX)
+IF(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(ENABLE_ANSI_MODE ON)
#exceptions:
IF(MINGW OR CYGWIN)
SET(ENABLE_ANSI_MODE OFF)
ENDIF(MINGW OR CYGWIN)
-ENDIF(CMAKE_COMPILER_IS_GNUCXX)
+ENDIF(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
OPTION(ENABLE_ANSI_MODE
"compile with -ansi flag"
@@ -109,7 +109,7 @@
#check flags...
INCLUDE (TestCXXAcceptsFlag)
-IF ( CMAKE_COMPILER_IS_GNUCC )
+IF ( CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang" )
CHECK_CXX_ACCEPTS_FLAG(-pg GccFlagPg)
IF ( GccFlagPg )
OPTION(ENABLE_GPROF
@@ -131,7 +131,7 @@
IF( ENABLE_ANSI_MODE )
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi")
ENDIF ( ENABLE_ANSI_MODE )
-ENDIF(CMAKE_COMPILER_IS_GNUCC)
+ENDIF(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
#Single output directory for building all executables and libraries.
@@ -163,7 +163,7 @@
SET(BUILD_CONTRIBS_LIB 1)
ENDIF ( BUILD_CONTRIBS )

View file

@ -1,5 +1,23 @@
--- src/contribs-lib/CLucene/analysis/de/GermanStemmer.cpp.orig 2011-03-16 20:21:07.000000000 -0400
+++ src/contribs-lib/CLucene/analysis/de/GermanStemmer.cpp 2013-01-08 17:03:27.000000000 -0500
+++ src/contribs-lib/CLucene/analysis/de/GermanStemmer.cpp 2013-03-27 17:12:31.000000000 -0400
@@ -16,7 +16,7 @@
}
TCHAR* GermanStemmer::stem(const TCHAR* term, size_t length) {
- if (length < 0) {
+ if (length <= 0) {
length = _tcslen(term);
}
@@ -38,7 +38,7 @@
}
bool GermanStemmer::isStemmable(const TCHAR* term, size_t length) const {
- if (length < 0) {
+ if (length <= 0) {
length = _tcslen(term);
}
for (size_t c = 0; c < length; c++) {
@@ -144,7 +144,7 @@
{
buffer.setCharAt( i, _T('$') );

View file

@ -0,0 +1,56 @@
--- src/contribs-lib/CLucene/highlighter/Highlighter.cpp.orig 2011-03-16 20:21:07.000000000 -0400
+++ src/contribs-lib/CLucene/highlighter/Highlighter.cpp 2013-03-27 19:05:00.000000000 -0400
@@ -214,8 +214,9 @@
int32_t startOffset;
int32_t endOffset;
int32_t lastEndOffset = 0;
+ int len;
_textFragmenter->start(text);
- TCHAR substringBuffer[LUCENE_MAX_WORD_LEN];
+ TCHAR substringBuffer[LUCENE_MAX_WORD_LEN+1];
TokenGroup* tokenGroup=_CLNEW TokenGroup();
@@ -229,8 +230,9 @@
startOffset = tokenGroup->getStartOffset();
endOffset = tokenGroup->getEndOffset();
- _tcsncpy(substringBuffer,text+startOffset,endOffset-startOffset);
- substringBuffer[endOffset-startOffset]=_T('\0');
+ len = cl_min(endOffset-startOffset,LUCENE_MAX_WORD_LEN);
+ _tcsncpy(substringBuffer,text+startOffset,len);
+ substringBuffer[len]=_T('\0');
TCHAR* encoded = _encoder->encodeText(substringBuffer);
TCHAR* markedUpText=_formatter->highlightTerm(encoded, tokenGroup);
@@ -238,9 +240,7 @@
//store any whitespace etc from between this and last group
if (startOffset > lastEndOffset){
- int len = startOffset-lastEndOffset;
- if ( len > LUCENE_MAX_FIELD_LEN )
- len = LUCENE_MAX_FIELD_LEN;
+ len = cl_min(startOffset-lastEndOffset,LUCENE_MAX_FIELD_LEN);
_tcsncpy(buffer,text+lastEndOffset,len);
buffer[len]=_T('\0');
@@ -287,8 +287,9 @@
startOffset = tokenGroup->getStartOffset();
endOffset = tokenGroup->getEndOffset();
- _tcsncpy(substringBuffer,text+startOffset,endOffset-startOffset);
- substringBuffer[endOffset-startOffset]=_T('\0');
+ len = cl_min(endOffset-startOffset,LUCENE_MAX_WORD_LEN);
+ _tcsncpy(substringBuffer,text+startOffset,len);
+ substringBuffer[len]=_T('\0');
TCHAR* encoded = _encoder->encodeText(substringBuffer);
TCHAR* markedUpText=_formatter->highlightTerm(encoded, tokenGroup);
@@ -393,6 +394,7 @@
}
}
)
+ return NULL;
}

View file

@ -0,0 +1,11 @@
--- src/contribs-lib/CLucene/highlighter/WeightedTerm.cpp.orig 2011-03-16 20:21:07.000000000 -0400
+++ src/contribs-lib/CLucene/highlighter/WeightedTerm.cpp 2013-03-27 16:51:33.000000000 -0400
@@ -73,7 +73,7 @@
* @param weight the weight associated with this term
*/
void WeightedTerm::setWeight(float_t weight) {
- this->_weight = _weight;
+ _weight = weight;
cachedHashCode = 0;
}

View file

@ -0,0 +1,11 @@
--- src/core/CLucene/index/IndexWriter.cpp.orig 2011-03-16 20:21:07.000000000 -0400
+++ src/core/CLucene/index/IndexWriter.cpp 2013-03-27 16:56:54.000000000 -0400
@@ -814,7 +814,7 @@
ensureOpen();
if (maxNumSegments < 1)
- _CLTHROWA(CL_ERR_IllegalArgument, "maxNumSegments must be >= 1; got " + maxNumSegments);
+ _CLTHROWA(CL_ERR_IllegalArgument, (string("maxNumSegments must be >= 1; got ") + Misc::toString(maxNumSegments)).c_str());
if (infoStream != NULL)
message("optimize: index now " + segString());

View file

@ -0,0 +1,21 @@
--- src/core/CLucene/search/ConstantScoreQuery.cpp.orig 2011-03-16 20:21:07.000000000 -0400
+++ src/core/CLucene/search/ConstantScoreQuery.cpp 2013-03-27 17:34:06.000000000 -0400
@@ -25,14 +25,17 @@
BitSet* bits;
const float_t theScore;
int32_t _doc;
+ bool shouldDelete;
public:
ConstantScorer(Similarity* similarity, IndexReader* reader, Weight* w, Filter* filter) : Scorer(similarity),
bits(filter->bits(reader)), theScore(w->getValue()), _doc(-1)
{
+ shouldDelete = filter->shouldDeleteBitSet(bits);
}
virtual ~ConstantScorer() {
- _CLLDELETE(bits);
+ if ( shouldDelete)
+ _CLLDELETE(bits);
}
bool next() {

View file

@ -0,0 +1,11 @@
--- src/core/CLucene/util/MD5Digester.cpp.orig 2011-03-16 20:21:07.000000000 -0400
+++ src/core/CLucene/util/MD5Digester.cpp 2013-03-27 17:16:18.000000000 -0400
@@ -82,7 +82,7 @@
for (nCount = 0; nCount < 16; nCount++)
{
cl_sprintf(chEach, 10, "%02x", md5Digest[nCount]);
- strncat(chBuffer, chEach, sizeof(chEach));
+ strncat(chBuffer, chEach, 2);
}
return STRDUP_AtoA(chBuffer);

View file

@ -1,11 +1,11 @@
--- src/core/CMakeLists.txt.orig 2011-03-16 20:21:07.000000000 -0400
+++ src/core/CMakeLists.txt 2012-08-07 14:12:31.000000000 -0400
+++ src/core/CMakeLists.txt 2013-03-27 16:32:49.000000000 -0400
@@ -252,13 +252,13 @@
set(CLUCENE_SOVERSION ${CLUCENE_SOVERSION})
")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/CLuceneConfig.cmake"
- DESTINATION ${LIB_DESTINATION}/CLuceneConfig.cmake)
+ DESTINATION ${LIB_DESTINATION}/CLucene)
+ DESTINATION %%DATADIR%%)
# install pkg-config file
IF(NOT WIN32)

View file

@ -1,5 +1,14 @@
--- src/shared/CMakeLists.txt.orig 2011-03-16 20:21:07.000000000 -0400
+++ src/shared/CMakeLists.txt 2012-08-07 13:31:00.000000000 -0400
+++ src/shared/CMakeLists.txt 2013-03-27 17:31:13.000000000 -0400
@@ -42,7 +42,7 @@
find_package(ZLIB)
IF ( ZLIB_FOUND )
SET ( EXTRA_LIBS ${EXTRA_LIBS} ${ZLIB_LIBRARY} )
-ELSEIF ( ZLIB_FOUND )
+ELSE ( ZLIB_FOUND )
MESSAGE( "ZLIB not found, using local: ${clucene-ext_SOURCE_DIR}/zlib" )
SET(ZLIB_INCLUDE_DIR ${clucene-ext_SOURCE_DIR}/zlib )
SET(ZLIB_LIBRARY ${clucene-ext_BINARY_DIR})
@@ -62,7 +62,7 @@
stdint.h unistd.h io.h direct.h sys/dir.h sys/ndir.h dirent.h wctype.h fcntl.h
stat.h sys/stat.h stdexcept errno.h fcntl.h windef.h windows.h wchar.h

View file

@ -0,0 +1,30 @@
--- src/shared/cmake/MacroCheckGccVisibility.cmake.orig 2011-03-16 20:21:07.000000000 -0400
+++ src/shared/cmake/MacroCheckGccVisibility.cmake 2013-03-27 15:02:55.000000000 -0400
@@ -6,7 +6,7 @@
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
macro(MACRO_CHECK_GCC_VISIBILITY GccVisibility)
- if (CMAKE_COMPILER_IS_GNUCXX)
+ if (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
include(CheckCXXCompilerFlag)
include(MacroEnsureVersion)
# visibility support
@@ -43,7 +43,7 @@
if (${GccVisibility} AND GCC_IS_NEWER_THAN_4_1 AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
- set (KDE4_C_FLAGS "${KDE4_C_FLAGS}" "-fvisibility=hidden")
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" "-fvisibility=hidden")
if (GCC_IS_NEWER_THAN_4_2)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
@@ -52,7 +52,7 @@
set (${GccVisibility} 0)
endif (${GccVisibility} AND GCC_IS_NEWER_THAN_4_1 AND NOT _GCC_COMPILED_WITH_BAD_ALLOCATOR)
- else (CMAKE_COMPILER_IS_GNUCXX)
+ else (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(${GccVisibility} FALSE)
- endif (CMAKE_COMPILER_IS_GNUCXX)
+ endif (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
endmacro(MACRO_CHECK_GCC_VISIBILITY)

View file

@ -348,7 +348,6 @@ include/CLucene/util/byteinputstream.h
include/CLucene/util/gzipcompressstream.h
include/CLucene/util/gzipinputstream.h
include/CLucene/util/streamarray.h
lib/CLucene/CLuceneConfig.cmake
lib/libclucene-contribs-lib.so
lib/libclucene-contribs-lib.so.1
lib/libclucene-contribs-lib.so.2.3.3.4
@ -359,7 +358,8 @@ lib/libclucene-shared.so
lib/libclucene-shared.so.1
lib/libclucene-shared.so.2.3.3.4
libdata/pkgconfig/libclucene-core.pc
@dirrm lib/CLucene
%%DATADIR%%/CLuceneConfig.cmake
@dirrm %%DATADIR%%
@dirrm include/CLucene/util
@dirrm include/CLucene/store
@dirrm include/CLucene/snowball/src_c