Skip to content

Commit 77297b9

Browse files
committed
Fix null-weight SelfEvent temp buffer and init_events null prop
Do not invent a short-lived weight buffer when weight_index < 0 (flag-only / INITIAL net_send); MOD may net_send that pointer and corrupt later queue / BBSaveState handling. Skip NET_RECEIVE INITIAL for NetCons whose target Prop is already freed.
1 parent d55851a commit 77297b9

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/nrncvode/netcvode.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,17 +2367,18 @@ void nrn_pnt_receive_by_weight_index(Point_process* pnt,
23672367
}
23682368
return;
23692369
}
2370-
// No NetCon owner (null-weight / flag-only path): short-lived buffer OK.
2370+
// No NetCon owner: flag-only SelfEvent (weight_ often nullptr from mech INITIAL
2371+
// net_send) or unresolved index. Preserve historical nullptr for zero-weight
2372+
// cases — do **not** invent a temp buffer when weight_index < 0, or MOD may
2373+
// net_send that stack pointer and corrupt later queue handling (TQueue UAF).
23712374
if (fornet) {
23722375
sync_netcon_weights_for_target(pnt, /*soa_to_heap*/ true);
23732376
}
23742377
double* buf = weight_heap;
23752378
std::vector<double> tmp;
2376-
if (!buf && n > 0) {
2379+
if (!buf && weight_index >= 0 && n > 0) {
23772380
tmp.resize(static_cast<std::size_t>(n), 0.);
23782381
buf = tmp.data();
2379-
}
2380-
if (weight_index >= 0 && n > 0 && buf) {
23812382
neuron::container::network::SelfEventFields::materialize_weight_block(weight_index, n, buf);
23822383
}
23832384
POINT_RECEIVE(type, pnt, buf, flag);
@@ -2934,8 +2935,9 @@ void NetCvode::init_events() {
29342935
ITERATE(q, nclist) {
29352936
Object* obj = OBJ(q);
29362937
auto* d = static_cast<NetCon*>(obj->u.this_pointer);
2937-
if (d->target_) {
2938-
int type = d->target_->prop->_type; // somehow prop is non-deterministically-null here
2938+
// target_ may outlive Prop (unlocated / free_one_point); skip dead targets.
2939+
if (d->target_ && d->target_->prop) {
2940+
int type = d->target_->prop->_type;
29392941
// Dual-write: INITIAL and HOC weight[] must share one value stream.
29402942
// SoA is HOC-primary; heap is the buffer for generated pnt_receive_init.
29412943
d->weights_soa_to_heap();

0 commit comments

Comments
 (0)