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

login
register
mail settings
Submitter Laurence Withers
Date July 14, 2011, 2:09 p.m.
Message ID <1310652570-23687-1-git-send-email-lwithers@guralp.com>
Download mbox | patch
Permalink /patch/104681/
State Superseded
Headers show

Comments

Laurence Withers - July 14, 2011, 2:09 p.m.
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@guralp.com>
Cc: Andy Fleming <afleming@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(-)

Patch

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;