Skip to content

Commit

Permalink
Modify jl_nth_union_component to be more robust in the case of trying…
Browse files Browse the repository at this point in the history
… to get an invalid 'n'. This can happen if a struct or array containing Unions gets allocated using 'uninitialized' memory and the corresponding union selector bytes may contain arbitrary values. In these cases, we always know that u->a (where 'u' is a Union type) is a valid, non-Union type, so just return that instead. Fixes #25310
  • Loading branch information
quinnj committed Jan 2, 2018
1 parent 2cc82d2 commit 80ffd2a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,12 @@ static jl_value_t *nth_union_component(jl_value_t *v, int *pi)

jl_value_t *jl_nth_union_component(jl_value_t *v, int i)
{
return nth_union_component(v, &i);
jl_value_t *ret = nth_union_component(v, &i);
if (!ret) {
jl_uniontype_t *u = (jl_uniontype_t *)v;
return u->a;
}
return ret;
}

// inverse of jl_nth_union_component
Expand Down

0 comments on commit 80ffd2a

Please sign in to comment.