From: Chris Packham <judge.packham@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH v2 3/5] lib/net_utils.c: make string_to_ip stricter
Date: Fri, 18 Jan 2013 14:35:30 +1300 [thread overview]
Message-ID: <1358472932-32083-4-git-send-email-judge.packham@gmail.com> (raw)
In-Reply-To: <1358472932-32083-1-git-send-email-judge.packham@gmail.com>
From: Chris Packham <chris.packham@alliedtelesis.co.nz>
Previously values greater than 255 were implicitly truncated. Add some
stricter checking to reject addresses with components >255.
With the input "1234192.168.1.1" the old behaviour would truncate the
address to 192.168.1.1. New behaviour rejects the string outright and
returns 0, which for the purposes of IP addresses can be considered an
error.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2: None
lib/net_utils.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/net_utils.c b/lib/net_utils.c
index b425a68..2b20ccb 100644
--- a/lib/net_utils.c
+++ b/lib/net_utils.c
@@ -39,8 +39,9 @@ IPaddr_t string_to_ip(const char *s)
for (addr=0, i=0; i<4; ++i) {
ulong val = s ? simple_strtoul(s, &e, 10) : 0;
+ if (val > 255)
+ return 0;
addr <<= 8;
- addr |= (val & 0xFF);
if (s) {
s = (*e) ? e+1 : e;
}
--
1.7.12.rc2.16.g034161a
next prev parent reply other threads:[~2013-01-18 1:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-18 1:35 [U-Boot] [RFC PATCH v2 0/5] Initial IPv6 support Chris Packham
2013-01-18 1:35 ` [U-Boot] [RFC PATCH v2 1/5] Initial net6.h Chris Packham
2013-01-18 21:15 ` Kim Phillips
2013-01-18 1:35 ` [U-Boot] [RFC PATCH v2 2/5] lib/vsprintf.c: add IPv6 compressed format %pI6c Chris Packham
2013-01-18 1:35 ` Chris Packham [this message]
2013-01-18 1:35 ` [U-Boot] [RFC PATCH v2 4/5] lib/net_utils.c: add string_to_ip6 Chris Packham
2013-01-18 1:35 ` [U-Boot] [RFC PATCH v2 5/5] common.h: add getenv_IP6addr Chris Packham
2013-01-18 8:20 ` [U-Boot] [RFC PATCH v2 0/5] Initial IPv6 support Albert ARIBAUD
2013-01-18 9:39 ` Chris Packham
2013-01-18 10:16 ` Sergey Lapin
2013-01-18 10:44 ` Wolfgang Denk
2013-01-18 18:41 ` Joe Hershberger
2013-01-20 9:47 ` Chris Packham
2013-01-20 9:44 ` Chris Packham
2013-01-20 21:00 ` Albert ARIBAUD
2013-01-20 21:25 ` Chris Packham
2013-01-21 0:51 ` Chris Packham
2013-01-21 12:37 ` Wolfgang Denk
2013-01-18 10:25 ` Wolfgang Denk
2013-01-18 10:23 ` Wolfgang Denk
2013-01-20 9:24 ` Chris Packham
2013-01-21 12:39 ` Wolfgang Denk
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=1358472932-32083-4-git-send-email-judge.packham@gmail.com \
--to=judge.packham@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox