From 846189b62c9640c29049c51e56d502131af7f165 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 22 Sep 2013 19:32:37 +0200 Subject: [PATCH] Check data from getenv("LIBNFC_LOG_LEVEL") and config file Problem reported by Coverity: CID 1090344 (#1 of 1): Use of untrusted string value (TAINTED_STRING) . tainted_string: Passing tainted string "res->log_level" to "log_init(nfc_context const *)", which cannot accept tainted data.[show details] --- libnfc/conf.c | 5 ++++- libnfc/log.c | 5 ++++- libnfc/nfc-internal.c | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libnfc/conf.c b/libnfc/conf.c index 7bda47d..307467f 100644 --- a/libnfc/conf.c +++ b/libnfc/conf.c @@ -125,7 +125,10 @@ conf_keyvalue_context(void *data, const char *key, const char *value) } else if (strcmp(key, "allow_intrusive_scan") == 0) { string_as_boolean(value, &(context->allow_intrusive_scan)); } else if (strcmp(key, "log_level") == 0) { - context->log_level = atoi(value); + int i = atoi(value); + if (i < 0) i = 0; + if (i > 3) i = 3; + context->log_level = i; } 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) { diff --git a/libnfc/log.c b/libnfc/log.c index 0144167..83615b3 100644 --- a/libnfc/log.c +++ b/libnfc/log.c @@ -87,7 +87,10 @@ log_put(const uint8_t group, const char *category, const uint8_t priority, const log_level = 1; #endif } else { - log_level = atoi(env_log_level); + int i = atoi(env_log_level); + if (i < 0) i = 0; + if (i > 3) i = 3; + log_level = i; } // printf("log_level = %"PRIu32" group = %"PRIu8" priority = %"PRIu8"\n", log_level, group, priority); diff --git a/libnfc/nfc-internal.c b/libnfc/nfc-internal.c index 031483e..37512b4 100644 --- a/libnfc/nfc-internal.c +++ b/libnfc/nfc-internal.c @@ -121,7 +121,10 @@ nfc_context_new(void) // log level envvar = getenv("LIBNFC_LOG_LEVEL"); if (envvar) { - res->log_level = atoi(envvar); + int i = atoi(envvar); + if (i < 0) i = 0; + if (i > 3) i = 3; + res->log_level = i; } #endif // ENVVARS