From: Jean Delvare <jdelvare@suse.de>
To: Linux I2C <linux-i2c@vger.kernel.org>
Subject: i2c-tools: i2cbusses: Avoid buffer overflows in sysfs paths
Date: Tue, 31 Oct 2017 08:16:04 +0100 [thread overview]
Message-ID: <20171031081604.18a9ca54@endymion> (raw)
sprintf isn't safe, use snprintf instead.
---
tools/i2cbusses.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
--- a/tools/i2cbusses.c
+++ b/tools/i2cbusses.c
@@ -220,18 +220,18 @@ struct i2c_adap *gather_i2c_busses(void)
/* this should work for kernels 2.6.5 or higher and */
/* is preferred because is unambiguous */
- sprintf(n, "%s/%s/name", sysfs, de->d_name);
+ snprintf(n, NAME_MAX, "%s/%s/name", sysfs, de->d_name);
f = fopen(n, "r");
/* this seems to work for ISA */
if(f == NULL) {
- sprintf(n, "%s/%s/device/name", sysfs, de->d_name);
+ snprintf(n, NAME_MAX, "%s/%s/device/name", sysfs, de->d_name);
f = fopen(n, "r");
}
/* non-ISA is much harder */
/* and this won't find the correct bus name if a driver
has more than one bus */
if(f == NULL) {
- sprintf(n, "%s/%s/device", sysfs, de->d_name);
+ snprintf(n, NAME_MAX, "%s/%s/device", sysfs, de->d_name);
if(!(ddir = opendir(n)))
continue;
while ((dde = readdir(ddir)) != NULL) {
@@ -240,8 +240,8 @@ struct i2c_adap *gather_i2c_busses(void)
if (!strcmp(dde->d_name, ".."))
continue;
if ((!strncmp(dde->d_name, "i2c-", 4))) {
- sprintf(n, "%s/%s/device/%s/name",
- sysfs, de->d_name, dde->d_name);
+ snprintf(n, NAME_MAX, "%s/%s/device/%s/name",
+ sysfs, de->d_name, dde->d_name);
if((f = fopen(n, "r")))
goto found;
}
--
Jean Delvare
SUSE L3 Support
next reply other threads:[~2017-10-31 7:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-31 7:16 Jean Delvare [this message]
2017-11-06 12:04 ` i2c-tools: i2cbusses: Avoid buffer overflows in sysfs paths Uwe Kleine-König
2017-11-08 8:57 ` Jean Delvare
2017-11-08 9:29 ` Uwe Kleine-König
2017-11-08 21:14 ` Jean Delvare
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171031081604.18a9ca54@endymion \
--to=jdelvare@suse.de \
--cc=linux-i2c@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).