Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
73f4b847
Commit
73f4b847
authored
May 03, 2011
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: fix FormFile nil pointer dereference on missing multipart form
R=rsc CC=golang-dev
https://golang.org/cl/4463042
parent
684e065d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
src/pkg/http/request.go
src/pkg/http/request.go
+5
-3
src/pkg/http/request_test.go
src/pkg/http/request_test.go
+28
-0
No files found.
src/pkg/http/request.go
View file @
73f4b847
...
@@ -715,9 +715,11 @@ func (r *Request) FormFile(key string) (multipart.File, *multipart.FileHeader, o
...
@@ -715,9 +715,11 @@ func (r *Request) FormFile(key string) (multipart.File, *multipart.FileHeader, o
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
}
}
if
fhs
:=
r
.
MultipartForm
.
File
[
key
];
len
(
fhs
)
>
0
{
if
r
.
MultipartForm
!=
nil
&&
r
.
MultipartForm
.
File
!=
nil
{
f
,
err
:=
fhs
[
0
]
.
Open
()
if
fhs
:=
r
.
MultipartForm
.
File
[
key
];
len
(
fhs
)
>
0
{
return
f
,
fhs
[
0
],
err
f
,
err
:=
fhs
[
0
]
.
Open
()
return
f
,
fhs
[
0
],
err
}
}
}
return
nil
,
nil
,
ErrMissingFile
return
nil
,
nil
,
ErrMissingFile
}
}
...
...
src/pkg/http/request_test.go
View file @
73f4b847
...
@@ -200,6 +200,29 @@ func TestMultipartRequestAuto(t *testing.T) {
...
@@ -200,6 +200,29 @@ func TestMultipartRequestAuto(t *testing.T) {
validateTestMultipartContents
(
t
,
req
,
true
)
validateTestMultipartContents
(
t
,
req
,
true
)
}
}
func
TestEmptyMultipartRequest
(
t
*
testing
.
T
)
{
// Test that FormValue and FormFile automatically invoke
// ParseMultipartForm and return the right values.
req
,
err
:=
NewRequest
(
"GET"
,
"/"
,
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"NewRequest err = %q"
,
err
)
}
testMissingFile
(
t
,
req
)
}
func
testMissingFile
(
t
*
testing
.
T
,
req
*
Request
)
{
f
,
fh
,
err
:=
req
.
FormFile
(
"missing"
)
if
f
!=
nil
{
t
.
Errorf
(
"FormFile file = %q, want nil"
,
f
,
nil
)
}
if
fh
!=
nil
{
t
.
Errorf
(
"FormFile file header = %q, want nil"
,
fh
,
nil
)
}
if
err
!=
ErrMissingFile
{
t
.
Errorf
(
"FormFile err = %q, want nil"
,
err
,
ErrMissingFile
)
}
}
func
newTestMultipartRequest
(
t
*
testing
.
T
)
*
Request
{
func
newTestMultipartRequest
(
t
*
testing
.
T
)
*
Request
{
b
:=
bytes
.
NewBufferString
(
strings
.
Replace
(
message
,
"
\n
"
,
"
\r\n
"
,
-
1
))
b
:=
bytes
.
NewBufferString
(
strings
.
Replace
(
message
,
"
\n
"
,
"
\r\n
"
,
-
1
))
req
,
err
:=
NewRequest
(
"POST"
,
"/"
,
b
)
req
,
err
:=
NewRequest
(
"POST"
,
"/"
,
b
)
...
@@ -218,6 +241,9 @@ func validateTestMultipartContents(t *testing.T, req *Request, allMem bool) {
...
@@ -218,6 +241,9 @@ func validateTestMultipartContents(t *testing.T, req *Request, allMem bool) {
if
g
,
e
:=
req
.
FormValue
(
"texta"
),
textaValue
;
g
!=
e
{
if
g
,
e
:=
req
.
FormValue
(
"texta"
),
textaValue
;
g
!=
e
{
t
.
Errorf
(
"texta value = %q, want %q"
,
g
,
e
)
t
.
Errorf
(
"texta value = %q, want %q"
,
g
,
e
)
}
}
if
g
:=
req
.
FormValue
(
"missing"
);
g
!=
""
{
t
.
Errorf
(
"missing value = %q, want empty string"
,
g
)
}
assertMem
:=
func
(
n
string
,
fd
multipart
.
File
)
{
assertMem
:=
func
(
n
string
,
fd
multipart
.
File
)
{
if
_
,
ok
:=
fd
.
(
*
os
.
File
);
ok
{
if
_
,
ok
:=
fd
.
(
*
os
.
File
);
ok
{
...
@@ -234,6 +260,8 @@ func validateTestMultipartContents(t *testing.T, req *Request, allMem bool) {
...
@@ -234,6 +260,8 @@ func validateTestMultipartContents(t *testing.T, req *Request, allMem bool) {
t
.
Errorf
(
"fileb has unexpected underlying type %T"
,
fd
)
t
.
Errorf
(
"fileb has unexpected underlying type %T"
,
fd
)
}
}
}
}
testMissingFile
(
t
,
req
)
}
}
func
testMultipartFile
(
t
*
testing
.
T
,
req
*
Request
,
key
,
expectFilename
,
expectContent
string
)
multipart
.
File
{
func
testMultipartFile
(
t
*
testing
.
T
,
req
*
Request
,
key
,
expectFilename
,
expectContent
string
)
multipart
.
File
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment