Skip to content

Commit b5323d1

Browse files
author
Ajo Robert
committed
Bug#25062396 - ASSERTION `CUR_SHAPE != GCALC_FUNCTION:: SHAPE_POINT' FAILED.
Invalid input parameters could lead to wrong result buffer. Which can cause an assert due to traversing to uninitialized pointers and abrupt exit or cyclic processing of the result buffer. Fix included handling of below scenarios. 1. Uninitialized structure elements. 2. Handling of NULL pointers. 3. Breakout from cyclic loops. 4. Wrong result object (Point with more than one coordinates). Change-Id: I9badfa248889bc4e2f460b77d6a4be5dd72a962a
1 parent 7577852 commit b5323d1

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

sql/gcalc_tools.cc

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -447,6 +447,11 @@ int Gcalc_result_receiver::complete_shape()
447447
}
448448
else
449449
{
450+
if (cur_shape == Gcalc_function::shape_point)
451+
{
452+
DBUG_RETURN(1);
453+
}
454+
450455
DBUG_ASSERT(cur_shape != Gcalc_function::shape_point);
451456
if (cur_shape == Gcalc_function::shape_hole ||
452457
cur_shape == Gcalc_function::shape_polygon)
@@ -1173,8 +1178,12 @@ int Gcalc_operation_reducer::get_polygon_result(res_point *cur,
11731178
{
11741179
DBUG_ENTER("Gcalc_operation_reducer::get_polygon_result");
11751180
res_point *glue= cur->glue;
1176-
glue->up->down= NULL;
1177-
free_result(glue);
1181+
if(glue)
1182+
{
1183+
if(glue->up)
1184+
glue->up->down= NULL;
1185+
free_result(glue);
1186+
}
11781187
DBUG_RETURN(get_result_thread(cur, storage, 1) ||
11791188
storage->complete_shape());
11801189
}
@@ -1261,10 +1270,21 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage)
12611270
DBUG_ENTER("Gcalc_operation_reducer::get_result");
12621271
Dynamic_array<Gcalc_result_receiver::chunk_info> chunks;
12631272
bool polygons_found= false;
1273+
int counter= 0;
12641274

12651275
*m_res_hook= NULL;
12661276
while (m_result)
12671277
{
1278+
/**
1279+
Handle cyclic graph scenario. This can occur due to invalid input
1280+
geometry. Ideally the comparison should be with length of the string.
1281+
We have choosen an arbitory number suitable for practical usecase's
1282+
due to the complexity involved in checking with the length.
1283+
*/
1284+
counter++;
1285+
if (counter > 10000)
1286+
DBUG_RETURN(1);
1287+
12681288
Gcalc_function::shape_type shape;
12691289
Gcalc_result_receiver::chunk_info chunk;
12701290

sql/gcalc_tools.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -353,6 +353,10 @@ class Gcalc_operation_reducer : public Gcalc_dyn_list
353353
bool intersection_point)
354354
{
355355
res_point *result= (res_point *) new_item();
356+
result->up= result->down= result->glue= NULL;
357+
result->set_outer_poly(NULL);
358+
result->pi= NULL;
359+
result->first_poly_node= NULL;
356360
*m_res_hook= result;
357361
result->prev_hook= m_res_hook;
358362
m_res_hook= &result->next;

0 commit comments

Comments
 (0)