From 9f411dc1d4dab0d990ab772dd6c3fb0def7ee402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Fri, 6 Oct 2017 23:37:05 +0200 Subject: [PATCH] Throw ParserError_InvalidKeymapCount if keymapCount == 0. --- right/src/config_parser/parse_config.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/right/src/config_parser/parse_config.c b/right/src/config_parser/parse_config.c index c620258..7e59aa0 100644 --- a/right/src/config_parser/parse_config.c +++ b/right/src/config_parser/parse_config.c @@ -28,38 +28,46 @@ parser_error_t ParseConfig(config_buffer_t *buffer) uint16_t keymapCount; (void)dataModelVersion; + if (moduleConfigurationCount > 255) { return ParserError_InvalidModuleConfigurationCount; } + for (uint8_t moduleConfigurationIdx = 0; moduleConfigurationIdx < moduleConfigurationCount; moduleConfigurationIdx++) { errorCode = parseModuleConfiguration(buffer); if (errorCode != ParserError_Success) { return errorCode; } } + macroCount = readCompactLength(buffer); if (macroCount > MAX_MACRO_NUM) { return ParserError_InvalidMacroCount; } + for (uint8_t macroIdx = 0; macroIdx < macroCount; macroIdx++) { errorCode = ParseMacro(buffer, macroIdx); if (errorCode != ParserError_Success) { return errorCode; } } + keymapCount = readCompactLength(buffer); - if (keymapCount > MAX_KEYMAP_NUM) { + if (keymapCount == 0 || keymapCount > MAX_KEYMAP_NUM) { return ParserError_InvalidKeymapCount; } + for (uint8_t keymapIdx = 0; keymapIdx < keymapCount; keymapIdx++) { errorCode = ParseKeymap(buffer, keymapIdx, keymapCount, macroCount); if (errorCode != ParserError_Success) { return errorCode; } } + if (!ParserRunDry) { AllKeymapsCount = keymapCount; AllMacrosCount = macroCount; } + return ParserError_Success; }