From 05cd9578369e47d35a352454031463c461d00891 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Tomko?= Date: Tue, 23 Nov 2021 15:05:43 +0100 Subject: [PATCH] tests: pcivpdtest: check return value of virCreateAnonymousFile MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes: 59c1bc3a0e25e6d725db41990f11e0b53137115d Fixes: 43820e4b8037680ec451761216750c6b139db67a Fixes: 600f580d623ae4077ddeb6c7cb24f8a315a7c73b Signed-off-by: Ján Tomko Reviewed-by: Kristína Hanicová --- tests/virpcivpdtest.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index 284350fe29..a6bf46b103 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -445,7 +445,8 @@ testVirPCIVPDReadVPDBytes(const void *opaque G_GNUC_UNUSED) dataLen = G_N_ELEMENTS(fullVPDExample) - 2; buf = g_malloc0(dataLen); - fd = virCreateAnonymousFile(fullVPDExample, dataLen); + if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0) + return -1; readBytes = virPCIVPDReadVPDBytes(fd, buf, dataLen, 0, &csum); @@ -481,7 +482,9 @@ testVirPCIVPDParseVPDStringResource(const void *opaque G_GNUC_UNUSED) }; dataLen = G_N_ELEMENTS(stringResExample); - fd = virCreateAnonymousFile(stringResExample, dataLen); + if ((fd = virCreateAnonymousFile(stringResExample, dataLen)) < 0) + return -1; + result = virPCIVPDParseVPDLargeResourceString(fd, 0, dataLen, &csum, res); VIR_FORCE_CLOSE(fd); @@ -551,7 +554,9 @@ testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UNUSED) }; dataLen = G_N_ELEMENTS(fullVPDExample); - fd = virCreateAnonymousFile(fullVPDExample, dataLen); + if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0) + return -1; + res = virPCIVPDParse(fd); VIR_FORCE_CLOSE(fd); @@ -619,7 +624,9 @@ testVirPCIVPDParseZeroLengthRW(const void *opaque G_GNUC_UNUSED) }; dataLen = G_N_ELEMENTS(fullVPDExample); - fd = virCreateAnonymousFile(fullVPDExample, dataLen); + if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0) + return -1; + res = virPCIVPDParse(fd); VIR_FORCE_CLOSE(fd); @@ -669,7 +676,9 @@ testVirPCIVPDParseNoRW(const void *opaque G_GNUC_UNUSED) }; dataLen = G_N_ELEMENTS(fullVPDExample); - fd = virCreateAnonymousFile(fullVPDExample, dataLen); + if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0) + return -1; + res = virPCIVPDParse(fd); VIR_FORCE_CLOSE(fd); @@ -722,7 +731,9 @@ testVirPCIVPDParseFullVPDSkipInvalidKeywords(const void *opaque G_GNUC_UNUSED) }; dataLen = G_N_ELEMENTS(fullVPDExample); - fd = virCreateAnonymousFile(fullVPDExample, dataLen); + if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0) + return -1; + res = virPCIVPDParse(fd); VIR_FORCE_CLOSE(fd); @@ -775,7 +786,9 @@ testVirPCIVPDParseFullVPDSkipInvalidValues(const void *opaque G_GNUC_UNUSED) }; dataLen = G_N_ELEMENTS(fullVPDExample); - fd = virCreateAnonymousFile(fullVPDExample, dataLen); + if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0) + return -1; + res = virPCIVPDParse(fd); VIR_FORCE_CLOSE(fd); @@ -951,7 +964,8 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_GNUC_UNUSED) g_autoptr(virPCIVPDResource) res = NULL; \ const uint8_t testCase[] = { invalidVPD }; \ dataLen = G_N_ELEMENTS(testCase); \ - fd = virCreateAnonymousFile(testCase, dataLen); \ + if ((fd = virCreateAnonymousFile(testCase, dataLen)) < 0) \ + return -1; \ if ((res = virPCIVPDParse(fd))) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ "Successfully parsed an invalid VPD - this is not expected"); \ -- 2.47.2