From d07807c80cffa32460c10ddb0f76ac49d9c00387 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 13 Jul 2015 13:40:21 -0400 Subject: [PATCH] Handle validation of inputs in efi_loadopt_create() better. efibootmgr tries to tell how much space it needs to allocate by passing in optional_data=NULL, optional_data_size=$SOMESIZE, and we're validating that both things are set way too early. Move that until after the "if (size==0) return sz;" check. Based on the bug report in issue#22 and pull#27 . Signed-off-by: Peter Jones --- src/loadopt.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/loadopt.c b/src/loadopt.c index a41f181..c22b4ec 100644 --- a/src/loadopt.c +++ b/src/loadopt.c @@ -36,12 +36,7 @@ efi_loadopt_create(uint8_t *buf, ssize_t size, uint32_t attributes, efidp dp, ssize_t dp_size, unsigned char *description, uint8_t *optional_data, size_t optional_data_size) { - if (!description || (!optional_data && optional_data_size != 0)) { - errno = EINVAL; - return -1; - } - - if (!dp && dp_size == 0) { + if (!description) { errno = EINVAL; return -1; } @@ -57,6 +52,16 @@ efi_loadopt_create(uint8_t *buf, ssize_t size, uint32_t attributes, return -1; } + if (!optional_data && optional_data_size != 0) { + errno = EINVAL; + return -1; + } + + if (!dp && dp_size == 0) { + errno = EINVAL; + return -1; + } + uint8_t *pos = buf; *(uint32_t *)pos = attributes; -- 2.11.0