diff options
author | khali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0> | 2014-01-30 12:45:23 +0000 |
---|---|---|
committer | khali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0> | 2014-01-30 12:45:23 +0000 |
commit | 428db5e394c3f4e2d6d40d34477186d06f6839a4 (patch) | |
tree | 11cd35c2d1039937f9dc30ddc3569601ed9f748a | |
parent | 4d3c6bc5cd31eaa6fbf5e36e8f62bc32ef35e1d9 (diff) | |
download | lm-sensors-428db5e394c3f4e2d6d40d34477186d06f6839a4.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.
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@6223 7894878c-1315-0410-8ee3-d5d059ff63e0
-rw-r--r-- | lib/sysfs.c | 7 |
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!"); |