mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-23 11:54:33 +00:00
Please use safer string handling in any code you're already touching.
http://www.gratisoft.us/todd/papers/strlcpy.html git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@3057 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
a9f8528a69
commit
1e5fefa045
1 file changed
+11
-7
+11
-7
@@ -142,19 +142,22 @@ int sensors_read_proc_chips(void)
|
||||
while (fgets(n, NAME_MAX, f)) {
|
||||
char *fstype = dirname; /* alias to keep the code readable */
|
||||
|
||||
if (sscanf(n, "%*[^ ] %[^ ] %[^ ] %*s\n", sysfs, fstype) == 2
|
||||
&& !strcasecmp(fstype, "sysfs")) {
|
||||
if (sscanf(n, "%*[^ ] %[^ ] %[^ ] %*s\n", sysfsmount, fstype)
|
||||
== 2 && !strcasecmp(fstype, "sysfs")) {
|
||||
foundsysfs++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
if (! foundsysfs)
|
||||
if (!foundsysfs) {
|
||||
memset(sysfsmount, '\0', sizeof(sysfsmount));
|
||||
goto proc;
|
||||
}
|
||||
|
||||
/* Try /sys/class/hwmon first (Linux 2.6.14 and up) */
|
||||
strcpy(sysfsmount, sysfs);
|
||||
strcat(sysfs, "/class/hwmon");
|
||||
strncpy(sysfs, sysfsmount, sizeof(sysfs) - 1);
|
||||
sysfs[sizeof(sysfs) - 1] = '\0';
|
||||
strncat(sysfs, "/class/hwmon", sizeof(sysfs) - strlen(sysfs) - 1);
|
||||
|
||||
dir = opendir(sysfs);
|
||||
if (! dir)
|
||||
@@ -200,8 +203,9 @@ int sensors_read_proc_chips(void)
|
||||
|
||||
oldsys:
|
||||
/* Fall back to /sys/bus/i2c (Linux 2.5 to 2.6.13) */
|
||||
strcpy(sysfs, sysfsmount);
|
||||
strcat(sysfs, "/bus/i2c/devices");
|
||||
strncpy(sysfs, sysfsmount, sizeof(sysfs) - 1);
|
||||
sysfs[sizeof(sysfs) - 1] = '\0';
|
||||
strncat(sysfs, "/bus/i2c/devices", sizeof(sysfs) - strlen(sysfs) - 1);
|
||||
|
||||
dir = opendir(sysfs);
|
||||
if (! dir)
|
||||
|
||||
Reference in new issue
Block a user