From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/4] Use snprintf() in network code
Date: Fri, 23 Sep 2011 14:15:26 -0400 [thread overview]
Message-ID: <201109231415.27466.vapier@gentoo.org> (raw)
In-Reply-To: <1316799532-20761-5-git-send-email-sjg@chromium.org>
On Friday, September 23, 2011 13:38:52 Simon Glass wrote:
> This tidies up network code to use snprintf() in most cases instead of
> sprintf(). A few functions remain as they require header file changes.
NAK to most of these. we pick local sized buffers that are known to not
overflow, or require circumstances that aren't really feasible.
3 examples (which are the first 3 changes in this patch) below ...
> --- a/net/eth.c
> +++ b/net/eth.c
>
> char buf[20];
> - sprintf(buf, "%pM", enetaddr);
> + snprintf(buf, sizeof(buf), "%pM", enetaddr);
a mac address will not take more than 19 bytes. unless the sprintf code is
completely busted, but if that's the case, we should fix that instead since
it'd be pretty fundamentally screwed.
> char enetvar[32];
> - sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
> + snprintf(enetvar, sizeof(enetvar), index ? "%s%daddr" : "%saddr",
> + base_name, index);
in order for this to overflow, we have to have 1000+ eth devices (maybe more?
i'd have to read the code closer)
> char enetvar[15];
> - sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
> + snprintf(enetvar, sizeof(enetvar),
> + index ? "eth%dmacskip" : "ethmacskip", index);
in order for this to overflow, we have to have 10000+ eth devices
please look at the realistic needs rather than blanket converting to snprintf
-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/20110923/0dca814e/attachment.pgp
next prev parent reply other threads:[~2011-09-23 18:15 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-23 17:38 [U-Boot] [PATCH 0/4] Buffer overruns in printf Simon Glass
2011-09-23 17:38 ` [U-Boot] [PATCH 1/4] Add limits.h to hold basic limits Simon Glass
2011-09-23 17:38 ` [U-Boot] [PATCH 2/4] Add safe vsnprintf and snprintf library functions Simon Glass
2011-09-23 23:56 ` Graeme Russ
2011-09-28 23:26 ` Sonny Rao
2011-09-29 0:00 ` Graeme Russ
2011-09-29 0:38 ` Sonny Rao
2011-09-29 0:44 ` Graeme Russ
2011-09-23 17:38 ` [U-Boot] [PATCH 3/4] Make printf and vprintf safe from buffer overruns Simon Glass
2011-09-23 18:36 ` Kumar Gala
2011-09-23 18:48 ` Simon Glass
2011-09-23 20:31 ` Mike Frysinger
2011-09-23 20:41 ` Simon Glass
2011-09-23 22:36 ` Mike Frysinger
2011-09-23 23:06 ` Simon Glass
2011-09-25 20:16 ` Wolfgang Denk
2011-09-25 20:14 ` Wolfgang Denk
2011-09-26 18:25 ` Simon Glass
2011-09-26 18:47 ` Wolfgang Denk
2011-09-26 19:02 ` Simon Glass
2011-09-23 17:38 ` [U-Boot] [PATCH 4/4] Use snprintf() in network code Simon Glass
2011-09-23 18:15 ` Mike Frysinger [this message]
2011-09-23 18:30 ` Simon Glass
2011-09-23 20:09 ` Mike Frysinger
2011-09-23 20:39 ` Simon Glass
2011-09-23 20:40 ` [U-Boot] [PATCH 0/4] Buffer overruns in printf Albert ARIBAUD
2011-09-23 20:46 ` Simon Glass
2011-09-24 9:37 ` Albert ARIBAUD
2011-09-24 14:00 ` Simon Glass
2011-09-25 8:40 ` Albert ARIBAUD
2011-09-25 14:50 ` Simon Glass
2011-09-26 11:20 ` Albert ARIBAUD
2011-09-26 17:50 ` Simon Glass
2011-09-26 18:36 ` Wolfgang Denk
2011-09-26 22:28 ` Scott Wood
2011-09-27 6:52 ` Albert ARIBAUD
2011-10-10 19:06 ` Simon Glass
2011-10-10 20:36 ` Wolfgang Denk
2011-10-10 20:42 ` Simon Glass
2011-09-25 20:04 ` Wolfgang Denk
2011-09-26 17:30 ` Simon Glass
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=201109231415.27466.vapier@gentoo.org \
--to=vapier@gentoo.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox