Merge pull request #85 from cyphar/fix-symlink-keyword
keywords: safely encode symlink keywords
This commit is contained in:
commit
0fd0d3ed55
3 changed files with 39 additions and 3 deletions
12
keywords.go
12
keywords.go
|
@ -297,7 +297,11 @@ var (
|
||||||
linkKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (string, error) {
|
linkKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (string, error) {
|
||||||
if sys, ok := info.Sys().(*tar.Header); ok {
|
if sys, ok := info.Sys().(*tar.Header); ok {
|
||||||
if sys.Linkname != "" {
|
if sys.Linkname != "" {
|
||||||
return fmt.Sprintf("link=%s", sys.Linkname), nil
|
linkname, err := Vis(sys.Linkname)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("link=%s", linkname), nil
|
||||||
}
|
}
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
@ -307,7 +311,11 @@ var (
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("link=%s", str), nil
|
linkname, err := Vis(str)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("link=%s", linkname), nil
|
||||||
}
|
}
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
6
tar.go
6
tar.go
|
@ -129,7 +129,11 @@ func (ts *tarStream) readHeaders() {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
linkname := KeyVal(kv).Value()
|
linkname, err := Unvis(KeyVal(kv).Value())
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
break
|
||||||
|
}
|
||||||
if _, ok := ts.hardlinks[linkname]; !ok {
|
if _, ok := ts.hardlinks[linkname]; !ok {
|
||||||
ts.hardlinks[linkname] = []string{hdr.Name}
|
ts.hardlinks[linkname] = []string{hdr.Name}
|
||||||
} else {
|
} else {
|
||||||
|
|
24
test/cli/0002.sh
Normal file
24
test/cli/0002.sh
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
name=$(basename $0)
|
||||||
|
root=$1
|
||||||
|
gomtree=$(readlink -f ${root}/gomtree)
|
||||||
|
t=$(mktemp -d /tmp/go-mtree.XXXXXX)
|
||||||
|
|
||||||
|
echo "[${name}] Running in ${t}"
|
||||||
|
# This test is for basic running check of manifest, and check against tar and file system
|
||||||
|
#
|
||||||
|
|
||||||
|
pushd ${root}
|
||||||
|
|
||||||
|
# Create a symlink with spaces in the entries.
|
||||||
|
mkdir ${t}/root
|
||||||
|
ln -s "this is a dummy symlink" ${t}/root/link
|
||||||
|
|
||||||
|
# Create manifest and check it against the same symlink.
|
||||||
|
${gomtree} -K link,sha256digest -c -p ${t}/root > ${t}/root.mtree
|
||||||
|
${gomtree} -K link,sha256digest -f ${t}/root.mtree -p ${t}/root
|
||||||
|
|
||||||
|
popd
|
||||||
|
rm -rf ${t}
|
Loading…
Reference in a new issue