From 53349c8c20e5534fc33d57a615a2aa9d44be6528 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 5 Dec 2012 16:41:44 +0100 Subject: [PATCH] Prevent from segfault if user add too many devices in configuration file(s) --- libnfc/conf.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libnfc/conf.c b/libnfc/conf.c index 8c46f31..e8c89cf 100644 --- a/libnfc/conf.c +++ b/libnfc/conf.c @@ -82,6 +82,8 @@ conf_parse_file(const char* filename, void (*conf_keyvalue)(void* data, const ch break; } } + + free(pmatch); return false; } @@ -98,11 +100,19 @@ conf_keyvalue_context(void *data, const char* key, const char* value) context->log_level = atoi(value); } else if (strcmp(key, "device.name") == 0) { if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count-1].name, "") != 0) { + if(context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Configuration exceeded maximum user-defined devices."); + return; + } context->user_defined_device_count++; } strcpy(context->user_defined_devices[context->user_defined_device_count-1].name, value); } else if (strcmp(key, "device.connstring") == 0) { if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count-1].connstring, "") != 0) { + if(context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Configuration exceeded maximum user-defined devices."); + return; + } context->user_defined_device_count++; } strcpy(context->user_defined_devices[context->user_defined_device_count-1].connstring, value);