From 00d3e4ac379d76d6fdaacb288af1b76a4c4ed326 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Mon, 25 May 2020 14:54:00 +0000 Subject: Adjust fwrandom() to return 0 for sucess, -1 for failure --- sys/arch/amd64/stand/efi32/efirng.c | 9 ++++++--- sys/arch/amd64/stand/efi64/efirng.c | 9 ++++++--- sys/arch/amd64/stand/efiboot/efirng.c | 9 ++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'sys/arch/amd64') diff --git a/sys/arch/amd64/stand/efi32/efirng.c b/sys/arch/amd64/stand/efi32/efirng.c index 0178c14551a..2f503909488 100644 --- a/sys/arch/amd64/stand/efi32/efirng.c +++ b/sys/arch/amd64/stand/efi32/efirng.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efirng.c,v 1.1 2019/05/11 02:33:34 mlarkin Exp $ */ +/* $OpenBSD: efirng.c,v 1.2 2020/05/25 14:53:59 deraadt Exp $ */ /* * Copyright (c) 2018 Mark Kettenis @@ -59,23 +59,25 @@ typedef struct _EFI_RNG_PROTOCOL { static EFI_GUID rng_guid = EFI_RNG_PROTOCOL_GUID; -void +int fwrandom(char *buf, size_t buflen) { EFI_STATUS status; EFI_RNG_PROTOCOL *rng = NULL; UINT8 *random; size_t i; + int ret = 0; status = EFI_CALL(BS->LocateProtocol, &rng_guid, NULL, (void **)&rng); if (rng == NULL || EFI_ERROR(status)) - return; + return -1; random = alloc(buflen); status = EFI_CALL(rng->GetRNG, rng, NULL, buflen, random); if (EFI_ERROR(status)) { printf("RNG GetRNG() failed (%d)\n", status); + ret = -1; goto out; } @@ -84,4 +86,5 @@ fwrandom(char *buf, size_t buflen) out: free(random, buflen); + return ret; } diff --git a/sys/arch/amd64/stand/efi64/efirng.c b/sys/arch/amd64/stand/efi64/efirng.c index 2caaaff34d6..2f503909488 100644 --- a/sys/arch/amd64/stand/efi64/efirng.c +++ b/sys/arch/amd64/stand/efi64/efirng.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efirng.c,v 1.1 2019/05/11 02:36:10 mlarkin Exp $ */ +/* $OpenBSD: efirng.c,v 1.2 2020/05/25 14:53:59 deraadt Exp $ */ /* * Copyright (c) 2018 Mark Kettenis @@ -59,23 +59,25 @@ typedef struct _EFI_RNG_PROTOCOL { static EFI_GUID rng_guid = EFI_RNG_PROTOCOL_GUID; -void +int fwrandom(char *buf, size_t buflen) { EFI_STATUS status; EFI_RNG_PROTOCOL *rng = NULL; UINT8 *random; size_t i; + int ret = 0; status = EFI_CALL(BS->LocateProtocol, &rng_guid, NULL, (void **)&rng); if (rng == NULL || EFI_ERROR(status)) - return; + return -1; random = alloc(buflen); status = EFI_CALL(rng->GetRNG, rng, NULL, buflen, random); if (EFI_ERROR(status)) { printf("RNG GetRNG() failed (%d)\n", status); + ret = -1; goto out; } @@ -84,4 +86,5 @@ fwrandom(char *buf, size_t buflen) out: free(random, buflen); + return ret; } diff --git a/sys/arch/amd64/stand/efiboot/efirng.c b/sys/arch/amd64/stand/efiboot/efirng.c index 7df4272c053..2f503909488 100644 --- a/sys/arch/amd64/stand/efiboot/efirng.c +++ b/sys/arch/amd64/stand/efiboot/efirng.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efirng.c,v 1.1 2019/05/05 19:17:03 kettenis Exp $ */ +/* $OpenBSD: efirng.c,v 1.2 2020/05/25 14:53:59 deraadt Exp $ */ /* * Copyright (c) 2018 Mark Kettenis @@ -59,23 +59,25 @@ typedef struct _EFI_RNG_PROTOCOL { static EFI_GUID rng_guid = EFI_RNG_PROTOCOL_GUID; -void +int fwrandom(char *buf, size_t buflen) { EFI_STATUS status; EFI_RNG_PROTOCOL *rng = NULL; UINT8 *random; size_t i; + int ret = 0; status = EFI_CALL(BS->LocateProtocol, &rng_guid, NULL, (void **)&rng); if (rng == NULL || EFI_ERROR(status)) - return; + return -1; random = alloc(buflen); status = EFI_CALL(rng->GetRNG, rng, NULL, buflen, random); if (EFI_ERROR(status)) { printf("RNG GetRNG() failed (%d)\n", status); + ret = -1; goto out; } @@ -84,4 +86,5 @@ fwrandom(char *buf, size_t buflen) out: free(random, buflen); + return ret; } -- cgit v1.2.3