[PATCH][V2] uefirtvariable: fix decalred VLA have zero size (LP: #1526815)

Ivan Hu ivan.hu at canonical.com
Tue Jan 5 03:11:46 UTC 2016


Static analysis from clang scan-build found a declared variable-length
array(VLA) has zero size, setvariable_insertvariable() declares data[datasize],
however, it is called when delete a variable as follows:
ret = setvariable_insertvariable(fw, attributes, 0, variablenametest,
&gtestguid1, datadiff); so got a declared data[0] declared.

For Setvariable, Firmware will respond base on the datasize, for example, zero
datasize means to delete the variable, the data buffer won't affect the
setvariable function, the simplest way to avoid clang scan-build complaint
is to add extra byte data buffer.

Signed-off-by: Ivan Hu <ivan.hu at canonical.com>
---
 src/uefi/uefirtvariable/uefirtvariable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
index b3c7559..8efa7b3 100644
--- a/src/uefi/uefirtvariable/uefirtvariable.c
+++ b/src/uefi/uefirtvariable/uefirtvariable.c
@@ -867,7 +867,7 @@ static int setvariable_insertvariable(
 	uint64_t status;
 	uint64_t dataindex;
 
-	uint8_t data[datasize];
+	uint8_t data[datasize + 1];
 
 	for (dataindex = 0; dataindex < datasize; dataindex++)
 		data[dataindex] = (uint8_t)dataindex + datadiff;
-- 
1.9.1




More information about the fwts-devel mailing list