Check rng return value when generating serial numbers in pki utility

This commit is contained in:
Tobias Brunner
2012-07-16 14:53:35 +02:00
committed by Martin Willi
parent 5668a99a12
commit e93bb353d5
2 changed files with 8 additions and 8 deletions
+4 -4
View File
@@ -356,11 +356,11 @@ static int issue()
error = "no random number generator found"; error = "no random number generator found";
goto end; goto end;
} }
rng->allocate_bytes(rng, 8, &serial); if (!rng_allocate_bytes_not_zero(rng, 8, &serial, FALSE))
while (*serial.ptr == 0x00)
{ {
/* we don't accept a serial number with leading zeroes */ error = "failed to generate serial number";
rng->get_bytes(rng, 1, serial.ptr); rng->destroy(rng);
goto end;
} }
rng->destroy(rng); rng->destroy(rng);
} }
+4 -4
View File
@@ -298,11 +298,11 @@ static int self()
error = "no random number generator found"; error = "no random number generator found";
goto end; goto end;
} }
rng->allocate_bytes(rng, 8, &serial); if (!rng_allocate_bytes_not_zero(rng, 8, &serial, FALSE))
while (*serial.ptr == 0x00)
{ {
/* we don't accept a serial number with leading zeroes */ error = "failed to generate serial number";
rng->get_bytes(rng, 1, serial.ptr); rng->destroy(rng);
goto end;
} }
rng->destroy(rng); rng->destroy(rng);
} }