From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] sprintf side effect, a bug?
Date: Tue, 27 Jan 2009 14:31:52 -0600 [thread overview]
Message-ID: <497F6F38.4070604@freescale.com> (raw)
In-Reply-To: <200901271419.36674.e.robertson.svg@gmail.com>
E Robertson wrote:
> I did the following:
> memcpy (gd->bd->bi_enetaddr, MACAddress, sizeof(gd->bd->bi_enetaddr));
> memcpy (dupMACAddress, MACAddress, sizeof(dupMACAddress));
>
> printf("Before %02X:%02X:%02X:%02X:%02X:%02X\n",dupMACAddress[0],
> dupMACAddress[1],
> dupMACAddress[2], dupMACAddress[3],
> dupMACAddress[4], dupMACAddress[5]);
>
> sprintf(env_ethaddr,"%02X:%02X:%02X:%02X:%02X:%02X",dupMACAddress[0],
> dupMACAddress[1],
> dupMACAddress[2], dupMACAddress[3],
> dupMACAddress[4], dupMACAddress[5]);
> printf("After %02X:%02X:%02X:%02X:%02X:%02X\n",dupMACAddress[0],
> dupMACAddress[1],
> dupMACAddress[2], dupMACAddress[3],
> dupMACAddress[4], dupMACAddress[5]);
> printf("ethaddr %02X:%02X:%02X:%02X:%02X:%02X\n",gd->bd->bi_enetaddr[0],
> gd->bd->bi_enetaddr[1],
> gd->bd->bi_enetaddr[2], gd->bd->bi_enetaddr[3],
> gd->bd->bi_enetaddr[4], gd->bd->bi_enetaddr[5]);
>
>
> and I got this:
>
> Before 00:04:A6:00:6A:E6
> After 36:00:A6:00:6A:E6
> ethaddr 00:04:A6:00:6A:E6
> Alse env_ethaddr has the correct correct.
Looks like you're overflowing a buffer -- 0x36 0x00 are the last two
bytes of the sprintf output. Where are env_ethaddr and dupMACaddress
defined?
-Scott
next prev parent reply other threads:[~2009-01-27 20:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-26 20:53 [U-Boot] sprintf side effect, a bug? E Robertson
2009-01-26 22:30 ` Wolfgang Denk
2009-01-27 20:19 ` E Robertson
2009-01-27 20:31 ` Scott Wood [this message]
2009-01-27 20:57 ` E Robertson
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=497F6F38.4070604@freescale.com \
--to=scottwood@freescale.com \
--cc=u-boot@lists.denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.