Skip to content

Commit 8979c53

Browse files
deadprogramburgrp
authored andcommitted
runtime: call initRand() before initHeap() during initialization.
The reason is that allocating without a heap is usually more visible than using an uninitialized random generator which is subtle and may lead to security vulnerabilities. Based on suggestion from @eliasnaur Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent a1de93b commit 8979c53

5 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/runtime/runtime_wasmentry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func wasmEntryReactor() {
3434
// Initialize the heap.
3535
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
3636
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
37-
initHeap()
3837
initRand()
38+
initHeap()
3939

4040
if hasScheduler {
4141
// A package initializer might do funky stuff like start a goroutine and

src/runtime/scheduler_cooperative.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ func sleep(duration int64) {
243243
// run is called by the program entry point to execute the go program.
244244
// With a scheduler, init and the main function are invoked in a goroutine before starting the scheduler.
245245
func run() {
246-
initHeap()
247246
initRand()
247+
initHeap()
248248
go func() {
249249
initAll()
250250
callMain()

src/runtime/scheduler_cores.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ func sleep(duration int64) {
135135
// This function is called on the first core in the system. It will wake up the
136136
// other cores when ready.
137137
func run() {
138-
initHeap()
139138
initRand()
139+
initHeap()
140140

141141
go func() {
142142
// Package initializers are currently run single-threaded.

src/runtime/scheduler_none.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var schedulerExit bool
2121
// run is called by the program entry point to execute the go program.
2222
// With the "none" scheduler, init and the main function are invoked directly.
2323
func run() {
24-
initHeap()
2524
initRand()
25+
initHeap()
2626
initAll()
2727
callMain()
2828
mainExited = true

src/runtime/scheduler_threads.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var (
2121
// Because we just use OS threads, we don't need to do anything special here. We
2222
// can just initialize everything and run main.main on the main thread.
2323
func run() {
24-
initHeap()
2524
initRand()
25+
initHeap()
2626
task.Init(stackTop)
2727
initAll()
2828
callMain()

0 commit comments

Comments
 (0)