mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-28 12:40:42 +00:00
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.
This commit is contained in:
1 parent
b9361dc088
commit
c29be769f1
1 file changed
+4
-3
+4
-3
@@ -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!");
|
||||
|
||||
Reference in new issue
Block a user