Skip to content

Commit 8ef7f6b

Browse files
Prevent a fault in ODBCAppender due to conversion to unsigned (#626)
1 parent 6f791f0 commit 8ef7f6b

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/main/cpp/odbcappender.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ void ODBCAppender::setOption(const LogString& option, const LogString& value)
176176
{
177177
if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("BUFFERSIZE"), LOG4CXX_STR("buffersize")))
178178
{
179-
setBufferSize((size_t)OptionConverter::toInt(value, 1));
179+
int parsed = OptionConverter::toInt(value, 1);
180+
if (parsed < 0)
181+
{
182+
parsed = 1;
183+
}
184+
setBufferSize((size_t) parsed);
180185
}
181186
else if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("PASSWORD"), LOG4CXX_STR("password")))
182187
{

src/test/cpp/db/odbcappendertestcase.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ODBCAppenderTestCase : public AppenderSkeletonTestCase
3939
//
4040
LOGUNIT_TEST(testDefaultThreshold);
4141
LOGUNIT_TEST(testSetOptionThreshold);
42+
LOGUNIT_TEST(testNegativeBufferSizeOption);
4243
//#define DataSourceName_Log4cxxTest_Is_Valid
4344
#ifdef DataSourceName_Log4cxxTest_Is_Valid
4445
LOGUNIT_TEST(testConnectUsingDSN);
@@ -59,6 +60,13 @@ class ODBCAppenderTestCase : public AppenderSkeletonTestCase
5960
LogManager::shutdown();
6061
}
6162

63+
void testNegativeBufferSizeOption()
64+
{
65+
db::ODBCAppender appender;
66+
appender.setOption(LOG4CXX_STR("BUFFERSIZE"), LOG4CXX_STR("-10"));
67+
LOGUNIT_ASSERT_EQUAL((size_t) 1, appender.getBufferSize());
68+
}
69+
6270
// 'odbcAppenderDSN-Log4cxxTest.xml' requires the data souce name 'Log4cxxTest'
6371
// containing a 'ApplicationLogs' database
6472
// with 'UnitTestLog' table

0 commit comments

Comments
 (0)