|
|
d3440c |
From def2845efacab3a3973fb0218ac5077a162f8f1e Mon Sep 17 00:00:00 2001
|
|
|
d3440c |
From: Jean Delvare <jdelvare@suse.de>
|
|
|
d3440c |
Date: Thu, 2 Nov 2017 16:17:50 +0100
|
|
|
d3440c |
Subject: [PATCH 1/3] i2c-tools: i2cbusses: Avoid buffer overflows in sysfs
|
|
|
d3440c |
paths
|
|
|
d3440c |
|
|
|
d3440c |
sprintf isn't safe, use snprintf instead.
|
|
|
d3440c |
---
|
|
|
d3440c |
CHANGES | 3 +++
|
|
|
d3440c |
tools/i2cbusses.c | 10 +++++-----
|
|
|
d3440c |
2 files changed, 8 insertions(+), 5 deletions(-)
|
|
|
d3440c |
|
|
|
d3440c |
diff --git a/CHANGES b/CHANGES
|
|
|
d3440c |
index 15ff761..539adb0 100644
|
|
|
d3440c |
--- a/CHANGES
|
|
|
d3440c |
+++ b/CHANGES
|
|
|
d3440c |
@@ -1,6 +1,9 @@
|
|
|
d3440c |
i2c-tools CHANGES
|
|
|
d3440c |
-----------------
|
|
|
d3440c |
|
|
|
d3440c |
+master
|
|
|
d3440c |
+ tools: Fix potential buffer overflows in i2cbusses
|
|
|
d3440c |
+
|
|
|
d3440c |
4.0 (2017-10-30)
|
|
|
d3440c |
tools: Fix build with recent compilers (gcc 4.6+)
|
|
|
d3440c |
Add examples to the manual pages
|
|
|
d3440c |
diff --git a/tools/i2cbusses.c b/tools/i2cbusses.c
|
|
|
d3440c |
index dad22ea..cb78cc7 100644
|
|
|
d3440c |
--- a/tools/i2cbusses.c
|
|
|
d3440c |
+++ b/tools/i2cbusses.c
|
|
|
d3440c |
@@ -220,18 +220,18 @@ struct i2c_adap *gather_i2c_busses(void)
|
|
|
d3440c |
|
|
|
d3440c |
/* this should work for kernels 2.6.5 or higher and */
|
|
|
d3440c |
/* is preferred because is unambiguous */
|
|
|
d3440c |
- sprintf(n, "%s/%s/name", sysfs, de->d_name);
|
|
|
d3440c |
+ snprintf(n, NAME_MAX, "%s/%s/name", sysfs, de->d_name);
|
|
|
d3440c |
f = fopen(n, "r");
|
|
|
d3440c |
/* this seems to work for ISA */
|
|
|
d3440c |
if(f == NULL) {
|
|
|
d3440c |
- sprintf(n, "%s/%s/device/name", sysfs, de->d_name);
|
|
|
d3440c |
+ snprintf(n, NAME_MAX, "%s/%s/device/name", sysfs, de->d_name);
|
|
|
d3440c |
f = fopen(n, "r");
|
|
|
d3440c |
}
|
|
|
d3440c |
/* non-ISA is much harder */
|
|
|
d3440c |
/* and this won't find the correct bus name if a driver
|
|
|
d3440c |
has more than one bus */
|
|
|
d3440c |
if(f == NULL) {
|
|
|
d3440c |
- sprintf(n, "%s/%s/device", sysfs, de->d_name);
|
|
|
d3440c |
+ snprintf(n, NAME_MAX, "%s/%s/device", sysfs, de->d_name);
|
|
|
d3440c |
if(!(ddir = opendir(n)))
|
|
|
d3440c |
continue;
|
|
|
d3440c |
while ((dde = readdir(ddir)) != NULL) {
|
|
|
d3440c |
@@ -240,8 +240,8 @@ struct i2c_adap *gather_i2c_busses(void)
|
|
|
d3440c |
if (!strcmp(dde->d_name, ".."))
|
|
|
d3440c |
continue;
|
|
|
d3440c |
if ((!strncmp(dde->d_name, "i2c-", 4))) {
|
|
|
d3440c |
- sprintf(n, "%s/%s/device/%s/name",
|
|
|
d3440c |
- sysfs, de->d_name, dde->d_name);
|
|
|
d3440c |
+ snprintf(n, NAME_MAX, "%s/%s/device/%s/name",
|
|
|
d3440c |
+ sysfs, de->d_name, dde->d_name);
|
|
|
d3440c |
if((f = fopen(n, "r")))
|
|
|
d3440c |
goto found;
|
|
|
d3440c |
}
|
|
|
d3440c |
--
|
|
|
d3440c |
2.14.3
|
|
|
d3440c |
|