mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-12-05 22:08:19 +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)) {
|
while (fgets(n, NAME_MAX, f)) {
|
||||||
char *fstype = dirname; /* alias to keep the code readable */
|
char *fstype = dirname; /* alias to keep the code readable */
|
||||||
|
|
||||||
if (sscanf(n, "%*[^ ] %[^ ] %[^ ] %*s\n", sysfs, fstype) == 2
|
if (sscanf(n, "%*[^ ] %[^ ] %[^ ] %*s\n", sysfsmount, fstype)
|
||||||
&& !strcasecmp(fstype, "sysfs")) {
|
== 2 && !strcasecmp(fstype, "sysfs")) {
|
||||||
foundsysfs++;
|
foundsysfs++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (! foundsysfs)
|
if (!foundsysfs) {
|
||||||
|
memset(sysfsmount, '\0', sizeof(sysfsmount));
|
||||||
goto proc;
|
goto proc;
|
||||||
|
}
|
||||||
|
|
||||||
/* Try /sys/class/hwmon first (Linux 2.6.14 and up) */
|
/* Try /sys/class/hwmon first (Linux 2.6.14 and up) */
|
||||||
strcpy(sysfsmount, sysfs);
|
strncpy(sysfs, sysfsmount, sizeof(sysfs) - 1);
|
||||||
strcat(sysfs, "/class/hwmon");
|
sysfs[sizeof(sysfs) - 1] = '\0';
|
||||||
|
strncat(sysfs, "/class/hwmon", sizeof(sysfs) - strlen(sysfs) - 1);
|
||||||
|
|
||||||
dir = opendir(sysfs);
|
dir = opendir(sysfs);
|
||||||
if (! dir)
|
if (! dir)
|
||||||
@@ -200,8 +203,9 @@ int sensors_read_proc_chips(void)
|
|||||||
|
|
||||||
oldsys:
|
oldsys:
|
||||||
/* Fall back to /sys/bus/i2c (Linux 2.5 to 2.6.13) */
|
/* Fall back to /sys/bus/i2c (Linux 2.5 to 2.6.13) */
|
||||||
strcpy(sysfs, sysfsmount);
|
strncpy(sysfs, sysfsmount, sizeof(sysfs) - 1);
|
||||||
strcat(sysfs, "/bus/i2c/devices");
|
sysfs[sizeof(sysfs) - 1] = '\0';
|
||||||
|
strncat(sysfs, "/bus/i2c/devices", sizeof(sysfs) - strlen(sysfs) - 1);
|
||||||
|
|
||||||
dir = opendir(sysfs);
|
dir = opendir(sysfs);
|
||||||
if (! dir)
|
if (! dir)
|
||||||
|
|||||||
Reference in new issue
Block a user