* [U-Boot] [PATCH] miiphy: use strcpy() not sprintf()
@ 2011-07-14 12:31 Laurence Withers
2011-07-14 13:49 ` Albert ARIBAUD
0 siblings, 1 reply; 4+ messages in thread
From: Laurence Withers @ 2011-07-14 12:31 UTC (permalink / raw)
To: u-boot
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 strcpy()
instead.
Signed-off-by: Laurence Withers <lwithers@guralp.com>
Cc: Andy Fleming <afleming@freescale.com>
---
common/miiphyutil.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/common/miiphyutil.c b/common/miiphyutil.c
index bcab74e..0ddf88e 100644
--- a/common/miiphyutil.c
+++ b/common/miiphyutil.c
@@ -141,7 +141,7 @@ 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);
+ strcpy(new_dev->name, name);
ldev->read = read;
ldev->write = write;
new_dev->priv = ldev;
--
1.7.2.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] miiphy: use strcpy() not sprintf()
2011-07-14 12:31 [U-Boot] [PATCH] miiphy: use strcpy() not sprintf() Laurence Withers
@ 2011-07-14 13:49 ` Albert ARIBAUD
2011-07-14 18:02 ` Mike Frysinger
0 siblings, 1 reply; 4+ messages in thread
From: Albert ARIBAUD @ 2011-07-14 13:49 UTC (permalink / raw)
To: u-boot
Hi Laurence,
Le 14/07/2011 14:31, Laurence Withers a ?crit :
> 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 strcpy()
> instead.
Please use strncpy() which will also guard against overflows.
Amicalement,
--
Albert.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] miiphy: use strcpy() not sprintf()
2011-07-14 13:49 ` Albert ARIBAUD
@ 2011-07-14 18:02 ` Mike Frysinger
2011-07-15 9:21 ` Laurence Withers
0 siblings, 1 reply; 4+ messages in thread
From: Mike Frysinger @ 2011-07-14 18:02 UTC (permalink / raw)
To: u-boot
On Thursday, July 14, 2011 09:49:23 Albert ARIBAUD wrote:
> Le 14/07/2011 14:31, Laurence Withers a ?crit :
> > 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 strcpy()
> > instead.
>
> Please use strncpy() which will also guard against overflows.
or BUG_ON(strlen(name) >= MDIO_NAME_LEN)
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110714/60a4ff1d/attachment.pgp
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] miiphy: use strcpy() not sprintf()
2011-07-14 18:02 ` Mike Frysinger
@ 2011-07-15 9:21 ` Laurence Withers
0 siblings, 0 replies; 4+ messages in thread
From: Laurence Withers @ 2011-07-15 9:21 UTC (permalink / raw)
To: u-boot
On Thu, Jul 14, 2011 at 02:02:42PM -0400, Mike Frysinger wrote:
> On Thursday, July 14, 2011 09:49:23 Albert ARIBAUD wrote:
> > Please use strncpy() which will also guard against overflows.
>
> or BUG_ON(strlen(name) >= MDIO_NAME_LEN)
> -mike
Patch v3 has both. The original code did have a check for the name
overflowing but BUG_ON() is IMO clearer so I switched to using it instead. I
kept strncpy() in v3, rather than just strcpy(), because it makes the code
robust against future edits. Thanks for the feedback.
Bye for now,
--
Laurence Withers, <lwithers@guralp.com> http://www.guralp.com/
Direct tel:+447753988197 or tel:+443333408643 Software Engineer
General support queries: <support@guralp.com> CMG-DCM CMG-EAM CMG-NAM
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-07-15 9:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-14 12:31 [U-Boot] [PATCH] miiphy: use strcpy() not sprintf() Laurence Withers
2011-07-14 13:49 ` Albert ARIBAUD
2011-07-14 18:02 ` Mike Frysinger
2011-07-15 9:21 ` Laurence Withers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox