Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(132)

Issue 60740044: code review 60740044: cmd/gc: fix nil pointer dereference (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 5 months ago by 0intro
Modified:
11 years, 4 months ago
Reviewers:
gobot, iant
CC:
golang-codereviews, dave_cheney.net, iant
Visibility:
Public.

Description

cmd/gc: fix nil pointer dereference

Patch Set 1 #

Patch Set 2 : diff -r 1a3006bc130f https://code.google.com/p/go #

Patch Set 3 : diff -r e2f19c96b7e2 https://code.google.com/p/go #

Patch Set 4 : diff -r e2f19c96b7e2 https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1 line, -1 line) Patch
M src/cmd/gc/typecheck.c View 1 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 13
0intro
Hello golang-codereviews@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
11 years, 5 months ago (2014-02-06 22:40:08 UTC) #1
dave_cheney.net
Thanks. The fix looks pretty straight forward. Is there an issue or a test that ...
11 years, 5 months ago (2014-02-06 22:43:59 UTC) #2
0intro
> Thanks. The fix looks pretty straight forward. Is there an issue or a > ...
11 years, 5 months ago (2014-02-06 22:51:06 UTC) #3
dave_cheney.net
Fair enough, looks like a test exists already. Please wait for Ian, Remy or rsc. ...
11 years, 5 months ago (2014-02-06 22:54:07 UTC) #4
0intro
> This fix looks fine to me but in the long run we > should ...
11 years, 4 months ago (2014-02-07 08:09:52 UTC) #5
iant
LGTM
11 years, 4 months ago (2014-02-07 14:14:26 UTC) #6
0intro
*** Submitted as https://code.google.com/p/go/source/detail?r=bf5dc5852b54 *** cmd/gc: fix nil pointer dereference LGTM=iant R=golang-codereviews, dave, iant CC=golang-codereviews ...
11 years, 4 months ago (2014-02-07 14:43:51 UTC) #7
gobot
This CL appears to have broken the darwin-386-cheney builder.
11 years, 4 months ago (2014-02-07 14:47:54 UTC) #8
0intro
> This CL appears to have broken the darwin-386-cheney builder. > > https://codereview.appspot.com/60740044/ Sorry, I've ...
11 years, 4 months ago (2014-02-07 15:28:29 UTC) #9
0intro
This change seems to work around the issue, but I'm wondering why n->type == T ...
11 years, 4 months ago (2014-02-07 17:04:45 UTC) #10
iant
On Fri, Feb 7, 2014 at 9:04 AM, David du Colombier <0intro@gmail.com> wrote: > This ...
11 years, 4 months ago (2014-02-07 18:36:41 UTC) #11
0intro
Sorry, I've got confused. n->ntype->type == T, thus typecheckdeftype() set n->type = T. Hence the ...
11 years, 4 months ago (2014-02-07 19:04:18 UTC) #12
0intro
11 years, 4 months ago (2014-02-07 22:52:00 UTC) #13
As an experiment, I did the following change, which
I believe may be closer to the expected behavior,
as far as I understand it.

--- a/src/cmd/gc/typecheck.c
+++ b/src/cmd/gc/typecheck.c
@@ -3009,7 +3009,7 @@
 static void
 typecheckdeftype(Node *n)
 {
-       int lno;
+       int lno, nerrors0;
        Type *t;
        NodeList *l;
 
@@ -3018,10 +3018,12 @@
        setlineno(n);
        n->type->sym = n->sym;
        n->typecheck = 1;
+       nerrors0 = nerrors;
        typecheck(&n->ntype, Etype);
        if((t = n->ntype->type) == T) {
                n->diag = 1;
-               n->type = T;
+               if (nerrors == nerrors0)
+                       n->type = T;
                goto ret;
        }
        if(n->type == T) {

With this change, 6g return the following errors:

% /usr/local/go/pkg/tool/linux_amd64/6g fixedbugs/issue5581.go
fixedbugs/issue5581.go:18: y.A undefined (type *Bar has no field or method A)
fixedbugs/issue5581.go:29: undefined: Blah

Previously, the output was:

% /usr/local/go/pkg/tool/linux_amd64/6g fixedbugs/issue5581.go
fixedbugs/issue5581.go:29: undefined: Blah

Where the this error is followed by a SIGSEGV caught in cmd/gc/lex.c:/^main.

And before Russ's change, the output was :

% /usr/local/go/pkg/tool/linux_amd64/6g fixedbugs/issue5581.go
fixedbugs/issue5581.go:14: invalid recursive type Bar
fixedbugs/issue5581.go:18: y.A undefined (type *Bar has no field or method A)
fixedbugs/issue5581.go:29: undefined: Blah

Where the "invalid recursive type Bar" error was incorrect.

Does it make sense? What could be a proper way to fix it?

Thanks.

-- 
David du Colombier
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b