Skip to content

Commit 87308c5

Browse files
committed
Bub#21067193 Correct absolute() when invalid position value is passed.
Add unit test.
1 parent 140fdd0 commit 87308c5

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

driver/mysql_ps_resultset.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
#include <string.h>
2929
#include <stdlib.h>
3030
#include <sstream>
31+
#include <limits>
3132
#include <boost/scoped_array.hpp>
3233

3334

@@ -134,7 +135,7 @@ MySQL_Prepared_ResultSet::absolute(const int new_pos)
134135
return true;
135136
}
136137
} else if (new_pos < 0) {
137-
if ((-new_pos) > (int) num_rows) {
138+
if ((-new_pos) > (int) num_rows || (new_pos == std::numeric_limits<int>::min())) {
138139
row_position = 0; /* before first new_pos */
139140
} else {
140141
row_position = num_rows - (-new_pos) + 1;

driver/mysql_resultset.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
#include <stdlib.h>
2929
#include <stdio.h>
3030
#include <sstream>
31+
#include <limits>
3132
#include <boost/scoped_array.hpp>
3233

3334
#include <cppconn/exception.h>
@@ -100,7 +101,7 @@ MySQL_ResultSet::absolute(const int new_pos)
100101
return true;
101102
}
102103
} else if (new_pos < 0) {
103-
if ((-new_pos) > (int) num_rows) {
104+
if ((-new_pos) > (int) num_rows || (new_pos == std::numeric_limits<int>::min())) {
104105
row_position = 0; /* before first new_pos */
105106
} else {
106107
row_position = num_rows - (-new_pos) + 1;

test/unit/bugs/bugs.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2626

2727
#include "bugs.h"
2828
#include <sstream>
29+
#include <limits>
2930
#include "driver/mysql_error.h"
3031

3132
namespace testsuite
@@ -856,6 +857,39 @@ void bugs::bug17218692()
856857
}
857858

858859

860+
}
861+
862+
void bugs::bug21067193()
863+
{
864+
logMsg("bugs::bug21067193");
865+
try
866+
{
867+
int x = std::numeric_limits<int>::max();
868+
int y = std::numeric_limits<int>::min();
869+
870+
871+
stmt->execute("DROP TABLE IF EXISTS bug21067193");
872+
stmt->execute("create table bug21067193(id int)");
873+
stmt->execute("insert into bug21067193 values(1),(2),(3)");
874+
875+
res.reset((stmt->setResultSetType(sql::ResultSet::TYPE_SCROLL_SENSITIVE)->executeQuery("select * from bug21067193")));
876+
877+
ASSERT_EQUALS(true, res->absolute(2));
878+
ASSERT_EQUALS(2, res->getInt(1));
879+
880+
ASSERT_EQUALS(true, res->absolute(-1));
881+
ASSERT_EQUALS(3, res->getInt(1));
882+
883+
ASSERT_EQUALS(false, res->absolute(std::numeric_limits<int>::min())); //Invalid position, Returns FALSE
884+
885+
}
886+
catch (sql::SQLException & e)
887+
{
888+
// Error....
889+
throw;
890+
}
891+
892+
859893
}
860894

861895
} /* namespace regression */

test/unit/bugs/bugs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class bugs : public unit_fixture
6464
TEST_CASE(bug14520822);
6565
TEST_CASE(bug17218692);
6666
TEST_CASE(bug21053335);
67+
TEST_CASE(bug21067193);
6768
}
6869

6970
/**
@@ -113,6 +114,8 @@ class bugs : public unit_fixture
113114

114115
void bug21053335();
115116

117+
void bug21067193();
118+
116119
};
117120

118121
REGISTER_FIXTURE(bugs);

0 commit comments

Comments
 (0)