Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 996c253

Browse files
committed
libgraphics: Correct error handling in MCGPathIterate()
In `MCGPathIterate()`, the `t_success` flag was not checked before invoking the `p_callback`. If the default case in the `switch` block was hit, this resulted in calling `p_callback` with uninitialised values from the stack. This patch addresses the issue in two ways: - All values in the stack are initialised at acquisition - The function now returns immediately on encountering a problem; the `t_success` flag has been removed entirely
1 parent 1f2f6a7 commit 996c253

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

libgraphics/src/path.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,22 +1163,20 @@ bool MCGPathIterate(MCGPathRef self, MCGPathIterateCallback p_callback, void *p_
11631163
{
11641164
if (!MCGPathIsValid(self))
11651165
return false;
1166-
1167-
bool t_success;
1168-
t_success = true;
1169-
1166+
11701167
MCGPoint t_points[3];
1171-
uint32_t t_point_count;
1172-
MCGPathCommand t_command;
1168+
uint32_t t_point_count = 0;
1169+
MCGPathCommand t_command = kMCGPathCommandEnd;
11731170

11741171
SkPath::Iter t_iter(*self->path, false);
11751172
SkPath::Verb t_verb;
11761173
SkPoint t_sk_points[4];
11771174

11781175
// IM-2015-03-20: [[ Bug 15035 ]] The first point returned by SkPath::Iter::next() is
11791176
// always the last moveTo point; the points for the current verb start at index 1.
1180-
while (t_success && (t_verb = t_iter.next(t_sk_points)) != SkPath::kDone_Verb)
1177+
while ((t_verb = t_iter.next(t_sk_points)) != SkPath::kDone_Verb)
11811178
{
1179+
11821180
switch(t_verb)
11831181
{
11841182
case SkPath::kMove_Verb:
@@ -1219,15 +1217,11 @@ bool MCGPathIterate(MCGPathRef self, MCGPathIterateCallback p_callback, void *p_
12191217

12201218
default:
12211219
// Unknown path instruction
1222-
t_success = false;
1223-
break;
1220+
return false;
12241221
}
1225-
1226-
t_success = p_callback(p_context, t_command, t_points, t_point_count);
1222+
if (!p_callback(p_context, t_command, t_points, t_point_count))
1223+
return false;
12271224
}
12281225

1229-
if (t_success)
1230-
t_success = p_callback(p_context, kMCGPathCommandEnd, nil, 0);
1231-
1232-
return t_success;
1226+
return p_callback(p_context, kMCGPathCommandEnd, nil, 0);
12331227
}

0 commit comments

Comments
 (0)