Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
25465347
Commit
25465347
authored
Nov 02, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
communicator/ssh: buffer file on disk to read length [GH-561]
parent
7f639d89
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
12 deletions
+34
-12
CHANGELOG.md
CHANGELOG.md
+2
-0
communicator/ssh/communicator.go
communicator/ssh/communicator.go
+32
-12
No files found.
CHANGELOG.md
View file @
25465347
...
...
@@ -13,6 +13,8 @@ BUG FIXES:
*
builder/openstack: Properly scrub password from logs [GH-554]
*
common/uuid: Use cryptographically secure PRNG when generating
UUIDs. [GH-552]
*
communicator/ssh: File uploads that exceed the size of memory no longer
cause crashes. [GH-561]
## 0.3.10 (October 20, 2013)
...
...
communicator/ssh/communicator.go
View file @
25465347
...
...
@@ -8,6 +8,7 @@ import (
"fmt"
"github.com/mitchellh/packer/packer"
"io"
"io/ioutil"
"log"
"net"
"os"
...
...
@@ -362,30 +363,49 @@ func checkSCPStatus(r *bufio.Reader) error {
}
func
scpUploadFile
(
dst
string
,
src
io
.
Reader
,
w
io
.
Writer
,
r
*
bufio
.
Reader
)
error
{
// Determine the length of the upload content by copying it
// into an in-memory buffer. Note that this means what we upload
// must fit into memory.
log
.
Println
(
"Copying input data into in-memory buffer so we can get the length"
)
inputBuf
:=
new
(
bytes
.
Buffer
)
if
_
,
err
:=
io
.
Copy
(
inputBuf
,
src
);
err
!=
nil
{
// Create a temporary file where we can copy the contents of the src
// so that we can determine the length, since SCP is length-prefixed.
tf
,
err
:=
ioutil
.
TempFile
(
""
,
"packer-upload"
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error creating temporary file for upload: %s"
,
err
)
}
defer
os
.
Remove
(
tf
.
Name
())
defer
tf
.
Close
()
log
.
Println
(
"Copying input data into temporary file so we can read the length"
)
if
_
,
err
:=
io
.
Copy
(
tf
,
src
);
err
!=
nil
{
return
err
}
// Sync the file so that the contents are definitely on disk, then
// read the length of it.
if
err
:=
tf
.
Sync
();
err
!=
nil
{
return
fmt
.
Errorf
(
"Error creating temporary file for upload: %s"
,
err
)
}
// Seek the file to the beginning so we can re-read all of it
if
_
,
err
:=
tf
.
Seek
(
0
,
0
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Error creating temporary file for upload: %s"
,
err
)
}
fi
,
err
:=
tf
.
Stat
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error creating temporary file for upload: %s"
,
err
)
}
// Start the protocol
log
.
Println
(
"Beginning file upload..."
)
fmt
.
Fprintln
(
w
,
"C0644"
,
inputBuf
.
Len
(),
dst
)
err
:=
checkSCPStatus
(
r
)
if
err
!=
nil
{
fmt
.
Fprintln
(
w
,
"C0644"
,
fi
.
Size
(),
dst
)
if
err
:=
checkSCPStatus
(
r
);
err
!=
nil
{
return
err
}
if
_
,
err
:=
io
.
Copy
(
w
,
inputBu
f
);
err
!=
nil
{
if
_
,
err
:=
io
.
Copy
(
w
,
t
f
);
err
!=
nil
{
return
err
}
fmt
.
Fprint
(
w
,
"
\x00
"
)
err
=
checkSCPStatus
(
r
)
if
err
!=
nil
{
if
err
:=
checkSCPStatus
(
r
);
err
!=
nil
{
return
err
}
...
...
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