From adc0f34eac148c9fa649d7b18ac079c97a1f4d50 Mon Sep 17 00:00:00 2001 From: Evan Su <48808396+HACKERALERT@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:28:52 -0400 Subject: [PATCH] check for rand.Read errors and panic Unlikely to happen but make sure to panic if rand.Read fails otherwise values may be zeroed arrays --- VERSION | 2 +- picocrypt/main.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index ed30379..52309be 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.06 +2.07 \ No newline at end of file diff --git a/picocrypt/main.go b/picocrypt/main.go index 9cd21c9..f914253 100644 --- a/picocrypt/main.go +++ b/picocrypt/main.go @@ -355,10 +355,18 @@ func work() int { flags[4] = 1 } _, errs[2] = fout.Write(rsEncode(rs5, flags)) - rand.Read(salt) - rand.Read(hkdfSalt) - rand.Read(serpentIV) - rand.Read(nonce) + if _, err := rand.Read(salt); err != nil { + panic(err) + } + if _, err := rand.Read(hkdfSalt); err != nil { + panic(err) + } + if _, err := rand.Read(serpentIV); err != nil { + panic(err) + } + if _, err := rand.Read(nonce); err != nil { + panic(err) + } _, errs[3] = fout.Write(rsEncode(rs16, salt)) _, errs[4] = fout.Write(rsEncode(rs32, hkdfSalt)) _, errs[5] = fout.Write(rsEncode(rs16, serpentIV))