[U-Boot] [PATCH v2] miiphy: use strncpy() not sprintf()

Laurence Withers lwithers at guralp.com
Thu Jul 14 16:09:30 CEST 2011


In miiphy_register() the new device's name was initialised by passing a
string parameter as the format string to sprintf(). As this would cause
problems if it ever contained a '%' symbol, switch to using strncpy()
instead.

Signed-off-by: Laurence Withers <lwithers at guralp.com>
Cc: Andy Fleming <afleming at freescale.com>
---
Changes for v2:
 - Use strncpy() rather than plain strcpy() for extra safety.
---
 common/miiphyutil.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/common/miiphyutil.c b/common/miiphyutil.c
index bcab74e..bc9896e 100644
--- a/common/miiphyutil.c
+++ b/common/miiphyutil.c
@@ -141,7 +141,8 @@ void miiphy_register(const char *name,
 	/* initalize mii_dev struct fields */
 	new_dev->read = legacy_miiphy_read;
 	new_dev->write = legacy_miiphy_write;
-	sprintf(new_dev->name, name);
+	strncpy(new_dev->name, name, MDIO_NAME_LEN);
+	new_dev->name[MDIO_NAME_LEN - 1] = 0;
 	ldev->read = read;
 	ldev->write = write;
 	new_dev->priv = ldev;
-- 
1.7.2.5



More information about the U-Boot mailing list