[go] net: Check length of input ip address before for loop

22 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Oct 1, 2022, 8:05:32 AM10/1/22
to goph...@pubsubhelper.golang.org, Mohamed Asheik, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

net: Check length of input ip address before for loop

Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
GitHub-Last-Rev: f69dff4ac673cff649a3526076f97f9733995705
GitHub-Pull-Request: golang/go#55987
---
M src/net/ip.go
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/net/ip.go b/src/net/ip.go
index 54c5288..604fe67 100644
--- a/src/net/ip.go
+++ b/src/net/ip.go
@@ -562,11 +562,11 @@
// Parse IPv4 address (d.d.d.d).
func parseIPv4(s string) IP {
var p [IPv4len]byte
+ if len(s) == 0 {
+ // Missing octets.
+ return nil
+ }
for i := 0; i < IPv4len; i++ {
- if len(s) == 0 {
- // Missing octets.
- return nil
- }
if i > 0 {
if s[0] != '.' {
return nil
@@ -719,6 +719,9 @@
// parseIPZone parses s as an IP address, return it and its associated zone
// identifier (IPv6 only).
func parseIPZone(s string) (IP, string) {
+ if len(s) == 0 {
+ return nil, ""
+ }
for i := 0; i < len(s); i++ {
switch s[i] {
case '.':

To view, visit change 437515. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
Gerrit-Change-Number: 437515
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: Mohamed Asheik <mohame...@gmail.com>
Gerrit-MessageType: newchange

Gopher Robot (Gerrit)

unread,
Oct 1, 2022, 8:06:07 AM10/1/22
to Gerrit Bot, Mohamed Asheik, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.

View Change

    To view, visit change 437515. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    Gerrit-Change-Number: 437515
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mohamed Asheik <mohame...@gmail.com>
    Gerrit-Comment-Date: Sat, 01 Oct 2022 12:06:02 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Gerrit Bot (Gerrit)

    unread,
    Oct 1, 2022, 9:22:18 AM10/1/22
    to Mohamed Asheik, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Damien Neil, Ian Lance Taylor.

    Gerrit Bot uploaded patch set #2 to this change.

    View Change

    net: Check length of input ip address before for loop

    It would be good if length of the given string is checked before for loop and return appropriate return value.


    Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    GitHub-Last-Rev: f69dff4ac673cff649a3526076f97f9733995705
    GitHub-Pull-Request: golang/go#55987
    ---
    M src/net/ip.go
    1 file changed, 20 insertions(+), 4 deletions(-)

    To view, visit change 437515. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    Gerrit-Change-Number: 437515
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mohamed Asheik <mohame...@gmail.com>
    Gerrit-Attention: Damien Neil <dn...@google.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-MessageType: newpatchset

    Ian Lance Taylor (Gerrit)

    unread,
    Oct 1, 2022, 9:28:59 AM10/1/22
    to Gerrit Bot, Mohamed Asheik, goph...@pubsubhelper.golang.org, Damien Neil, Ian Lance Taylor, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Damien Neil.

    View Change

    1 comment:

    • File src/net/ip.go:

      • Patch Set #2, Line 565: if len(s) == 0 {

        The variable s is changed during the loop. This patch changes the behavior of the coffee.

    To view, visit change 437515. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    Gerrit-Change-Number: 437515
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mohamed Asheik <mohame...@gmail.com>
    Gerrit-Attention: Damien Neil <dn...@google.com>
    Gerrit-Comment-Date: Sat, 01 Oct 2022 13:28:54 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Gerrit Bot (Gerrit)

    unread,
    Oct 1, 2022, 9:45:18 AM10/1/22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Damien Neil.

    Gerrit Bot uploaded patch set #3 to this change.

    View Change

    net: Check length of input ip address before for loop

    It would be good if length of the given string is checked before for loop and return appropriate return value.

    Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    GitHub-Last-Rev: 6a844376f6ab28538f33ab91dcd124496d3ab77b

    GitHub-Pull-Request: golang/go#55987
    ---
    M src/net/ip.go
    1 file changed, 19 insertions(+), 0 deletions(-)

    To view, visit change 437515. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    Gerrit-Change-Number: 437515
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mohamed Asheik <mohame...@gmail.com>
    Gerrit-Attention: Damien Neil <dn...@google.com>
    Gerrit-MessageType: newpatchset

    Gerrit Bot (Gerrit)

    unread,
    Oct 2, 2022, 1:37:16 AM10/2/22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Ian Lance Taylor.

    Gerrit Bot uploaded patch set #4 to this change.

    View Change

    net: check length of input ip address before for loop


    It would be good if length of the given string is checked before for loop and return appropriate return value.

    Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    GitHub-Last-Rev: 6a844376f6ab28538f33ab91dcd124496d3ab77b
    GitHub-Pull-Request: golang/go#55987
    ---
    M src/net/ip.go
    1 file changed, 19 insertions(+), 0 deletions(-)

    To view, visit change 437515. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    Gerrit-Change-Number: 437515
    Gerrit-PatchSet: 4
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mohamed Asheik <mohame...@gmail.com>

    Mohamed Asheik (Gerrit)

    unread,
    Oct 2, 2022, 9:44:05 PM10/2/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Damien Neil, Ian Lance Taylor, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Ian Lance Taylor.

    View Change

    1 comment:

    • File src/net/ip.go:

      • Patch Set #2, Line 565: if len(s) == 0 {

        The variable s is changed during the loop. This patch changes the behavior of the coffee.

      • Ack, added len check in the beginning and unchanged the loop logic, Pls review

    To view, visit change 437515. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    Gerrit-Change-Number: 437515
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mohamed Asheik <mohame...@gmail.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Comment-Date: Sun, 02 Oct 2022 05:35:44 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Ian Lance Taylor <ia...@golang.org>
    Gerrit-MessageType: comment

    Ian Lance Taylor (Gerrit)

    unread,
    Oct 2, 2022, 10:04:22 PM10/2/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Damien Neil, Ian Lance Taylor, Gopher Robot, Mohamed Asheik, golang-co...@googlegroups.com

    View Change

    1 comment:

    • Patchset:

      • Patch Set #4:

        Thanks, but I don't see any reason to do this. It's very unlikely that anybody will call these functions with an empty string, and it seems to me that if they do the right thing will happen. There's no reason to add an extra check for an unlikely case.

    To view, visit change 437515. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    Gerrit-Change-Number: 437515
    Gerrit-PatchSet: 4
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mohamed Asheik <mohame...@gmail.com>
    Gerrit-Comment-Date: Mon, 03 Oct 2022 02:04:19 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Gerrit Bot (Gerrit)

    unread,
    Oct 9, 2022, 10:10:05 AM10/9/22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Gerrit Bot uploaded patch set #5 to this change.

    View Change

    net: check length of input ip address before for loop

    It would be good if length of the given string is checked before for loop and return appropriate return value.

    Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    GitHub-Last-Rev: 8f6a4f0b4ccfeb0e2d3ed498e257caef96092237

    GitHub-Pull-Request: golang/go#55987
    ---
    M src/net/ip.go
    1 file changed, 19 insertions(+), 0 deletions(-)

    To view, visit change 437515. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    Gerrit-Change-Number: 437515
    Gerrit-PatchSet: 5
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mohamed Asheik <mohame...@gmail.com>
    Gerrit-MessageType: newpatchset

    Gopher Robot (Gerrit)

    unread,
    Oct 9, 2022, 10:23:13 AM10/9/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Damien Neil, Ian Lance Taylor, Mohamed Asheik, golang-co...@googlegroups.com

    Gopher Robot abandoned this change.

    View Change

    Abandoned GitHub PR golang/go#55987 has been closed.

    To view, visit change 437515. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I04c962272f24e95c6bfcec0c70fa5a32b7f482c7
    Gerrit-Change-Number: 437515
    Gerrit-PatchSet: 5
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Mohamed Asheik <mohame...@gmail.com>
    Gerrit-MessageType: abandon
    Reply all
    Reply to author
    Forward
    0 new messages