Skip to content

Commit 0fb5fa0

Browse files
authored
staticdata: Don't use newm pointer after it has been invalidated (JuliaLang#57471)
The buffer may end up reallocated by the additional writes performed to it in this function.
1 parent a70818c commit 0fb5fa0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/staticdata.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,10 @@ static void jl_write_module(jl_serializer_state *s, uintptr_t item, jl_module_t
13441344
arraylist_push(&s->relocs_list, (void*)(reloc_offset + offsetof(jl_module_t, usings_backedges)));
13451345
arraylist_push(&s->relocs_list, (void*)backref_id(s, m->usings_backedges, s->link_ids_relocs));
13461346

1347+
// After reload, everything that has happened in this process happened semantically at
1348+
// (for .incremental) or before jl_require_world, so reset this flag.
1349+
jl_atomic_store_relaxed(&newm->export_set_changed_since_require_world, 0);
1350+
13471351
// write out the usings list
13481352
memset(&newm->usings._space, 0, sizeof(newm->usings._space));
13491353
if (m->usings.items == &m->usings._space[0]) {
@@ -1372,6 +1376,7 @@ static void jl_write_module(jl_serializer_state *s, uintptr_t item, jl_module_t
13721376
newm->usings.items = (void**)tot;
13731377
arraylist_push(&s->relocs_list, (void*)(reloc_offset + offsetof(jl_module_t, usings.items)));
13741378
arraylist_push(&s->relocs_list, (void*)(((uintptr_t)DataRef << RELOC_TAG_OFFSET) + item));
1379+
newm = NULL; // `write_*(s->s)` below may invalidate `newm`, so defensively set it to NULL
13751380
size_t i;
13761381
for (i = 0; i < module_usings_length(m); i++) {
13771382
struct _jl_module_using *data = module_usings_getidx(m, i);
@@ -1395,10 +1400,6 @@ static void jl_write_module(jl_serializer_state *s, uintptr_t item, jl_module_t
13951400
}
13961401
}
13971402
assert(ios_pos(s->s) - reloc_offset == tot);
1398-
1399-
// After reload, everything that has happened in this process happened semantically at
1400-
// (for .incremental) or before jl_require_world, so reset this flag.
1401-
jl_atomic_store_relaxed(&newm->export_set_changed_since_require_world, 0);
14021403
}
14031404

14041405
static void record_memoryref(jl_serializer_state *s, size_t reloc_offset, jl_genericmemoryref_t ref) {

0 commit comments

Comments
 (0)