From patchwork Tue Mar 5 21:54:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Fleming X-Patchwork-Id: 225187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id C80F12C0369 for ; Wed, 6 Mar 2013 08:55:04 +1100 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1UCzp9-0001Kv-OA; Tue, 05 Mar 2013 21:55:03 +0000 Received: from arkanian.console-pimps.org ([212.110.184.194]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1UCzp7-0001KU-Mh for fwts-devel@lists.ubuntu.com; Tue, 05 Mar 2013 21:55:01 +0000 Received: by arkanian.console-pimps.org (Postfix, from userid 1002) id A29196C063; Tue, 5 Mar 2013 21:55:01 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on arkanian.vm.bytemark.co.uk X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=unavailable version=3.3.1 Received: from localhost (unknown [151.224.133.121]) by arkanian.console-pimps.org (Postfix) with ESMTPSA id 6CD076C05D; Tue, 5 Mar 2013 21:54:59 +0000 (GMT) From: Matt Fleming To: fwts-devel@lists.ubuntu.com Subject: [PATCH 3/3] uefirtvariable: Test GetNextVariableName() error handling Date: Tue, 5 Mar 2013 21:54:54 +0000 Message-Id: <1362520494-8917-4-git-send-email-matt@console-pimps.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1362520494-8917-1-git-send-email-matt@console-pimps.org> References: <1362520494-8917-1-git-send-email-matt@console-pimps.org> Cc: Matt Fleming X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com From: Matt Fleming The spec is pretty clear about what status codes should be returned when passing bogus parameters to GetNextVariableName(), such as a NULL pointer for VariableName returning EFI_INVALID_PARAMETER. Make sure we see the status codes we expect. Also, check to see that VariableNameSize is updated with the size of the data buffer required to hold VariableName when GetNextVariableName() returns EFI_BUFFER_TOO_SMALL. Signed-off-by: Matt Fleming Acked-by: Colin Ian King Acked-by: Ivan Hu --- src/uefi/uefirtvariable/uefirtvariable.c | 93 ++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c index fe4cdce..c8f0911 100644 --- a/src/uefi/uefirtvariable/uefirtvariable.c +++ b/src/uefi/uefirtvariable/uefirtvariable.c @@ -556,6 +556,95 @@ err: return FWTS_ERROR; } +static int getnextvariable_test4(fwts_framework *fw) +{ + long ioret; + uint64_t status; + uint64_t i; + + struct efi_getnextvariablename getnextvariablename; + uint64_t variablenamesize = MAX_DATA_LENGTH; + uint16_t variablename[MAX_DATA_LENGTH]; + EFI_GUID vendorguid; + + getnextvariablename.VariableNameSize = &variablenamesize; + getnextvariablename.VendorGuid = &vendorguid; + getnextvariablename.status = &status; + + /* + * Check for expected error values. + */ + getnextvariablename.VariableName = NULL; + + ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename); + + if (ioret != -1 || status != EFI_INVALID_PARAMETER) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableName", + "Expected EFI_INVALID_PARAMETER with NULL VariableName."); + fwts_uefi_print_status_info(fw, status); + goto err; + } + + getnextvariablename.VariableName = variablename; + getnextvariablename.VendorGuid = NULL; + + ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename); + + if (ioret != -1 || status != EFI_INVALID_PARAMETER) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableName", + "Expected EFI_INVALID_PARAMETER with NULL VendorGuid."); + fwts_uefi_print_status_info(fw, status); + goto err; + } + + getnextvariablename.VendorGuid = &vendorguid; + getnextvariablename.VariableNameSize = NULL; + + ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename); + + if (ioret != -1 || status != EFI_INVALID_PARAMETER) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableName", + "Expected EFI_INVALID_PARAMETER with NULL VariableNameSize."); + fwts_uefi_print_status_info(fw, status); + goto err; + } + + /* No first result can be 0 or 1 byte in size. */ + for (i = 0; i < 2; i++) { + variablenamesize = i; + getnextvariablename.VariableNameSize = &variablenamesize; + + /* To start the search, need to pass a Null-terminated string in VariableName */ + variablename[0] = '\0'; + + ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename); + + /* + * We expect this machine to have at least some UEFI + * variables, which is the reason we don't check for + * EFI_NOT_FOUND at this point. + */ + if (ioret != -1 || status != EFI_BUFFER_TOO_SMALL) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableName", + "Expected EFI_BUFFER_TOO_SMALL with small VariableNameSize."); + fwts_uefi_print_status_info(fw, status); + goto err; + } + + /* Has the firmware failed to update the variable size? */ + if (variablenamesize == i) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableName", + "EFI_BUFFER_TOO_SMALL VariableNameSize was not updated."); + goto err; + } + } + + return FWTS_OK; + +err: + return FWTS_ERROR; +} + static int setvariable_insertvariable(fwts_framework *fw, uint32_t attributes, uint64_t datasize, uint16_t *varname, EFI_GUID *gtestguid, uint8_t datadiff) { @@ -1086,6 +1175,10 @@ static int uefirtvariable_test2(fwts_framework *fw) if (ret != FWTS_OK) return ret; + ret = getnextvariable_test4(fw); + if (ret != FWTS_OK) + return ret; + fwts_passed(fw, "UEFI runtime service GetNextVariableName interface test passed."); return FWTS_OK;