Check stk before dereferencing

This commit fixes #7022 - I've added an additional check to ensure that
stk is not null before dereferencing it to get it's next element,
assigning NULL if it is itself NULL.
Assert stk rather than checking null

Given that a big stack is never requested before allocating an initial
stack segment, having a non-null stk member here is an invariant.
auto merge of #7033 : influenza/rust/rust-7022, r=brson

This commit fixes #7022 - I've added an additional check to ensure that
stk is not null before dereferencing it to get it's next element,
assigning NULL if it is itself NULL.