mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-07-04 06:38:30 +00:00
keywords: safely encode symlink keywords
symlink(2) is a very dumb syscall, and allows you to put any damn value you please inside a symlink. In addition, spaces are valid path characters which causes issues with keyword parsing. So use Vis() and Unvis() to safely store an encoded version of the path. This also adds a cli test for this behaviour. Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
parent
30ae0132eb
commit
704d91fc7c
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) {
|
||||
if sys, ok := info.Sys().(*tar.Header); ok {
|
||||
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
|
||||
}
|
||||
|
@ -307,7 +311,11 @@ var (
|
|||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue