[Skiboot] [PATCH] Fix FTBFS with -Werror=format-overflow

Frédéric Bonnard frediz at linux.vnet.ibm.com
Fri Jan 26 00:14:55 AEDT 2018


i2c.c fails to compile with gcc7 and -Werror=format-overflow used in
Debian Unstable and Ubuntu 18.04 :

i2c.c: In function ‘i2c_init’:
i2c.c:211:15: error: ‘%s’ directive writing up to 255 bytes into a
region of size 236 [-Werror=format-overflow=]

We just make sure we never write more than what the destination can
store.

Signed-off-by: Frédéric Bonnard <frediz at linux.vnet.ibm.com>
---
 external/opal-prd/i2c.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/external/opal-prd/i2c.c b/external/opal-prd/i2c.c
index ba4b3c85..dca303e4 100644
--- a/external/opal-prd/i2c.c
+++ b/external/opal-prd/i2c.c
@@ -234,7 +234,13 @@ void i2c_init(void)
 			continue;
 
 		/* Get bus name */
-		sprintf(dpath, SYSFS "/class/i2c-dev/%s/name", devent->d_name);
+		if (snprintf(dpath, NAME_MAX, SYSFS "/class/i2c-dev/%s/name",
+					devent->d_name) < 0 ) {
+			pr_log(LOG_ERR, "I2C: bus name longer than NAME_MAX : "
+					SYSFS "/class/i2c-dev/%s/name",
+					devent->d_name);
+			return;
+		}
 		f = fopen(dpath, "r");
 		if (!f) {
 			pr_log(LOG_NOTICE, "I2C: Can't open %s: %m, skipping.",
-- 
2.11.0



More information about the Skiboot mailing list