diff options
author | Tobias Brunner <tobias@strongswan.org> | 2012-06-25 16:03:53 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-07-16 14:53:35 +0200 |
commit | e93bb353d5b2750b3a89751a83086108e3d7c1ca (patch) | |
tree | 3640f0eb2f9f0ecd59acd70d4e0bf6a150f84e58 /src | |
parent | 5668a99a12a47b13a7b1b3f875cc90e9a29b5cac (diff) | |
download | strongswan-e93bb353d5b2750b3a89751a83086108e3d7c1ca.tar.bz2 strongswan-e93bb353d5b2750b3a89751a83086108e3d7c1ca.tar.xz |
Check rng return value when generating serial numbers in pki utility
Diffstat (limited to 'src')
-rw-r--r-- | src/pki/commands/issue.c | 8 | ||||
-rw-r--r-- | src/pki/commands/self.c | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/pki/commands/issue.c b/src/pki/commands/issue.c index 0398c9dc9..4dbe2e069 100644 --- a/src/pki/commands/issue.c +++ b/src/pki/commands/issue.c @@ -356,11 +356,11 @@ static int issue() error = "no random number generator found"; goto end; } - rng->allocate_bytes(rng, 8, &serial); - while (*serial.ptr == 0x00) + if (!rng_allocate_bytes_not_zero(rng, 8, &serial, FALSE)) { - /* we don't accept a serial number with leading zeroes */ - rng->get_bytes(rng, 1, serial.ptr); + error = "failed to generate serial number"; + rng->destroy(rng); + goto end; } rng->destroy(rng); } diff --git a/src/pki/commands/self.c b/src/pki/commands/self.c index 6813c98f7..e98f90f4e 100644 --- a/src/pki/commands/self.c +++ b/src/pki/commands/self.c @@ -298,11 +298,11 @@ static int self() error = "no random number generator found"; goto end; } - rng->allocate_bytes(rng, 8, &serial); - while (*serial.ptr == 0x00) + if (!rng_allocate_bytes_not_zero(rng, 8, &serial, FALSE)) { - /* we don't accept a serial number with leading zeroes */ - rng->get_bytes(rng, 1, serial.ptr); + error = "failed to generate serial number"; + rng->destroy(rng); + goto end; } rng->destroy(rng); } |