From f778c5c25847a6e819902af9d60b9921bba3bd0f Mon Sep 17 00:00:00 2001 From: Dustin Graves Date: Mon, 4 Apr 2016 11:14:01 -0600 Subject: [PATCH] layers: Fix paramcheck struct array NULL indexing Fixes an issue where the generated parameter_validation code could index a NULL pointer to an array of structs. Change-Id: If78f1c97ea256911d857b0b8009b38e6ca6f2581 --- generator.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/generator.py b/generator.py index 84d7edc1..ebdd024f 100644 --- a/generator.py +++ b/generator.py @@ -3372,22 +3372,30 @@ class ParamCheckerOutputGenerator(OutputGenerator): checkExpr += '\n' + indent if lenParam: # Need to process all elements in the array - checkExpr += 'for (uint32_t i = 0; i < {}{}; ++i) {{\n'.format(valuePrefix, lenParam.name) + checkExpr += 'if ({}{} != NULL) {{\n'.format(valuePrefix, value.name) + indent = self.incIndent(indent) + checkExpr += indent + 'for (uint32_t i = 0; i < {}{}; ++i) {{\n'.format(valuePrefix, lenParam.name) indent = self.incIndent(indent) checkExpr += indent + 'skipCall |= parameter_validation_{}(report_data, {}, {}, {}, &({}{}[i]));\n'.format(value.type, name, prefix, isInput, valuePrefix, value.name) indent = self.decIndent(indent) checkExpr += indent + '}\n' + indent = self.decIndent(indent) + checkExpr += indent + '}\n' else: checkExpr += 'skipCall |= parameter_validation_{}(report_data, {}, {}, {}, {}{});\n'.format(value.type, name, prefix, isInput, valuePrefix, value.name) else: # Validation function does not have an isInput field if lenParam: # Need to process all elements in the array - expr = 'for (uint32_t i = 0; i < {}{}; ++i) {{\n'.format(valuePrefix, lenParam.name) + expr = 'if ({}{} != NULL) {{\n'.format(valuePrefix, value.name) + indent = self.incIndent(indent) + expr += indent + 'for (uint32_t i = 0; i < {}{}; ++i) {{\n'.format(valuePrefix, lenParam.name) indent = self.incIndent(indent) expr += indent + 'skipCall |= parameter_validation_{}(report_data, {}, {}, &({}{}[i]));\n'.format(value.type, name, prefix, valuePrefix, value.name) indent = self.decIndent(indent) expr += indent + '}\n' + indent = self.decIndent(indent) + expr += indent + '}\n' else: expr = 'skipCall |= parameter_validation_{}(report_data, {}, {}, {}{});\n'.format(value.type, name, prefix, valuePrefix, value.name) # -- 2.34.1