Skip to content

Commit

Permalink
Bug#26911453 UBSAN ERROR ON SETRINGORDERTEST.SETRINGORDERCCW UNIT TEST
Browse files Browse the repository at this point in the history
Fix misc UBSAN warnings in unit tests.
To repeat:
export UBSAN_OPTIONS="print_stacktrace=1"

./runtime_output_directory/merge_large_tests-t --gtest_filter='-*DeathTest*' > /dev/null

unittest/gunit/gis_algos-t.cc:78:70:
runtime error: downcast of address 0x000012dc0be8 which does not point to an object of type 'Gis_polygon_ring'

include/sql_string.h:683:35: runtime error: null pointer passed as argument 2, which is declared to never be null
    #1 0x373e7af in histograms::Value_map<String>::add_values(String const&, unsigned long long) sql/histograms/value_map.cc:149
    #2 0x294fcf2 in dd_column_statistics_unittest::add_values(histograms::Value_map<String>&) unittest/gunit/dd_column_statistics-t.cc:62

runtime_output_directory/merge_keyring_file_tests-t --gtest_filter='-*DeathTest*' > /dev/null

plugin/keyring/common/keyring_key.cc:82:57: runtime error: null pointer passed as argument 2, which is declared to never be null

Change-Id: I2651362e3373244b72e6893f0e22e67402b49a52
(cherry picked from commit 1fe3f72561994da1d912a257689e1b18106f8828)
  • Loading branch information
Tor Didriksen committed Oct 5, 2017
1 parent d620927 commit 85cb553
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/sql_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ class String
char *ret= static_cast<char*>(alloc_root(root, m_length + 1));
if (ret != NULL)
{
memcpy(ret, m_ptr, m_length);
if (m_length > 0)
memcpy(ret, m_ptr, m_length);
ret[m_length]= 0;
}
return ret;
Expand Down
3 changes: 2 additions & 1 deletion plugin/keyring/common/keyring_key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ void Key::store_field_length(uchar *buffer, size_t *buffer_position, size_t leng

void Key::store_field(uchar *buffer, size_t *buffer_position, const char *field, size_t field_length) const
{
memcpy(buffer + *buffer_position, field, field_length);
if (field_length > 0)
memcpy(buffer + *buffer_position, field, field_length);
*buffer_position+= field_length;
}

Expand Down
6 changes: 3 additions & 3 deletions unittest/gunit/gis_algos-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ void SetRingOrderTest::set_order_and_compare(const std::string &s1,
wkt.set(s1.c_str(), s1.length(), latincc);
wkt2.set(s2.c_str(), s2.length(), latincc);

Gis_polygon_ring *ringp= static_cast<Gis_polygon_ring *>
Gis_line_string *ringp= static_cast<Gis_line_string *>
(geometry_from_text(wkt, &str, &buffer));
DBUG_ASSERT(ringp->get_geotype() == Geometry::wkb_linestring);
Gis_polygon_ring ring(ringp->get_ptr(),
ringp->get_nbytes(), my_flags, 0U);
EXPECT_EQ(ring.set_ring_order(want_ccw), false);


ringp= static_cast<Gis_polygon_ring *>(geometry_from_text(wkt2, &str2,
ringp= static_cast<Gis_line_string *>(geometry_from_text(wkt2, &str2,
&buffer2));
DBUG_ASSERT(ringp->get_geotype() == Geometry::wkb_linestring);
Gis_polygon_ring ring2(ringp->get_ptr(),
Expand Down Expand Up @@ -155,7 +155,7 @@ TEST_F(SetRingOrderTest, RingDegradedToPointTest)
std::string s1("linestring(0 0, 0 0, 0 0, 0 0, 0 0)");
wkt.set(s1.c_str(), s1.length(), latincc);

Gis_polygon_ring *ringp= static_cast<Gis_polygon_ring *>
Gis_line_string *ringp= static_cast<Gis_line_string *>
(geometry_from_text(wkt, &str, &buffer));
DBUG_ASSERT(ringp->get_geotype() == Geometry::wkb_linestring);
Gis_polygon_ring ring(ringp->get_ptr(),
Expand Down

0 comments on commit 85cb553

Please sign in to comment.