summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2014-01-30 12:45:23 +0000
committerJean Delvare <khali@linux-fr.org>2014-01-30 12:45:23 +0000
commitc29be769f180d6bca9e995cff9ab7bbeea433949 (patch)
tree11cd35c2d1039937f9dc30ddc3569601ed9f748a /lib
parentb9361dc088985af79384e36b3e9ae3a9a1f20af6 (diff)
downloadlm-sensors-git-c29be769f180d6bca9e995cff9ab7bbeea433949.tar.gz
libsensors: Avoid insane memory allocations
While there is no longer a hard limit to the number of sensor of a given type per chip, I feel a little uncomfortable having no limit at all on the amount of memory we may try to allocate. Add an arbitrary safety limit so that a design error or a bug in a hwmon driver can't result into an insane memory allocation.
Diffstat (limited to 'lib')
-rw-r--r--lib/sysfs.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/sysfs.c b/lib/sysfs.c
index 89ad4001..74d58d6e 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -1,7 +1,7 @@
/*
sysfs.c - Part of libsensors, a library for reading Linux sensor data
Copyright (c) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
- Copyright (C) 2007-2010 Jean Delvare <khali@linux-fr.org>
+ Copyright (C) 2007-2014 Jean Delvare <khali@linux-fr.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -468,8 +468,9 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
break;
}
- /* Skip invalid entries */
- if (nr < 0) {
+ /* Skip invalid entries. The high limit is arbitrary, we just
+ don't want to allocate an insane amount of memory. */
+ if (nr < 0 || nr >= 1024) {
#ifdef DEBUG
sensors_fatal_error(__func__,
"Invalid channel number!");