summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2023-05-24 00:02:51 +0000
committerriastradh <riastradh@NetBSD.org>2023-05-24 00:02:51 +0000
commit42d3fefefe6a90c17461807a5ca5939d1e25903b (patch)
tree8d459fad59b86b4726a27f2345c1a8d022802253 /sys/dev
parentd94c79851afa7383aaf01c6dfdb6f4404172960e (diff)
efi(4): Fix logic to handle buffer sizing.
Can't KASSERT(datasize <= databufsize) because the caller is allowed to pass in a too-small size and get ERR_BUFFER_TOO_SMALL back, with the actual size returned so it can resize its buffer. So just clamp the size to the smaller of what the caller provided and what the firwmare provided, instead of asserting anything. PR kern/57076 XXX pullup-10
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/efi.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/sys/dev/efi.c b/sys/dev/efi.c
index d97dcfa4fd9..69fff66e086 100644
--- a/sys/dev/efi.c
+++ b/sys/dev/efi.c
@@ -1,4 +1,4 @@
-/* $NetBSD: efi.c,v 1.8 2023/05/22 16:28:16 riastradh Exp $ */
+/* $NetBSD: efi.c,v 1.9 2023/05/24 00:02:51 riastradh Exp $ */
/*-
* Copyright (c) 2021 Jared McNeill <jmcneill@invisible.ca>
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.8 2023/05/22 16:28:16 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.9 2023/05/24 00:02:51 riastradh Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@@ -377,10 +377,10 @@ efi_ioctl_var_get(struct efi_var_ioc *var)
error = efi_status_to_error(status);
goto done;
}
- KASSERT(datasize <= databufsize);
var->datasize = datasize;
- if (status == EFI_SUCCESS && databuf != NULL) {
- error = copyout(databuf, var->data, var->datasize);
+ if (status == EFI_SUCCESS && databufsize != 0) {
+ error = copyout(databuf, var->data,
+ MIN(datasize, databufsize));
} else {
var->data = NULL;
}
@@ -423,10 +423,10 @@ efi_ioctl_var_next(struct efi_var_ioc *var)
error = efi_status_to_error(status);
goto done;
}
- KASSERT(namesize <= namebufsize);
var->namesize = namesize;
if (status == EFI_SUCCESS) {
- error = copyout(namebuf, var->name, var->namesize);
+ error = copyout(namebuf, var->name,
+ MIN(namesize, namebufsize));
} else {
var->name = NULL;
}