fix parseInfoFile does not handle spaces in filenames#38977
fix parseInfoFile does not handle spaces in filenames#38977kolyshkin merged 1 commit intomoby:masterfrom
Conversation
|
ping @kolyshkin @cpuguy83 PTAL |
c668e38 to
d17e07a
Compare
There was a problem hiding this comment.
According to kernel sources, the only characters replaced by \nnn are space, tab, newline, and backslash (\).
Initially I was opposed to using strconv.Unquote() but it seems if \ is always escaped, Unquote can do no harm.
BTW, note that Linux file paths can indeed contain newlines, tabs, and backslashes :=0
There was a problem hiding this comment.
There's no need to have a temp variable here, since you exit on error anyway, so maybe
root.Mountpoint, err := strconv.Unquote(`"` + fields[4] + `"`)
if err != nil {
 return nil, errors.Wrapf(err, "Can't parse mount point %q", fields[4])
}(I have also made error message smaller, but it's up to you)
There was a problem hiding this comment.
Yes, I wanted to do a follow up to fix the error messages (also make them lowercase); for this fix, I went for consistency with the existing ones.
kolyshkin
left a comment
There was a problem hiding this comment.
Added a few comments, but it's all very minor nitpicks so LGTM
|
BTW this needs to be ported to containerd, too. (as a side note, I am puzzled why I haven't fixed this as part of https://github.com/moby/moby/pull/36091as I was very much aware of the issue) |
d17e07a to
57de474
Compare
Codecov Report
@@ Coverage Diff @@
## master #38977 +/- ##
=========================================
Coverage ? 36.89%
=========================================
Files ? 614
Lines ? 45414
Branches ? 0
=========================================
Hits ? 16756
Misses ? 26365
Partials ? 2293 |
|
Updated; removed the intermediate variable (no other changes) |
`/proc/self/mountinfo` uses `\040` for spaces, however, `parseInfoFile()`
did not decode those spaces in paths, therefore attempting to use `\040`
as a literal part of the path.
This patch un-quotes the `root` and `mount point` fields to fix
situations where paths contain spaces.
Note that the `mount source` field is not modified, given that
this field is documented (man `PROC(5)`) as:
filesystem-specific information or "none"
Which I interpreted as "the format in this field is undefined".
Reported-by: Daniil Yaroslavtsev <[email protected]>
Reported-by: Nathan Ringo <[email protected]>
Based-on-patch-by: Diego Becciolini <[email protected]>
Based-on-patch-by: Sergei Utinski <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
57de474 to
58d8625
Compare
Moby PR #38977 [1] and containerd PR #3159 [2] added the handing of escape sequences in mountinfo paths (root and mountpoint fields). Unfortunately, it also broke the handling of paths containing double quotes, as it was pointed out in [3]. The solution is to stop using strconv.Unquote and write our own specialized function to deal with escape sequences. Unit tests added. [1] moby/moby#38977 [2] containerd/containerd#3159 [3] containerd/containerd#4257 Signed-off-by: Kir Kolyshkin <[email protected]>
Moby PR #38977 [1] and containerd PR #3159 [2] added the handing of escape sequences in mountinfo paths (root and mountpoint fields). Unfortunately, it also broke the handling of paths containing double quotes, as it was pointed out in [3]. The solution is to stop using strconv.Unquote and write our own specialized function to deal with escape sequences. Unit tests added. [1] moby/moby#38977 [2] containerd/containerd#3159 [3] containerd/containerd#4257 Signed-off-by: Kir Kolyshkin <[email protected]>
Moby PR #38977 [1] and containerd PR #3159 [2] added the handing of escape sequences in mountinfo paths (root and mountpoint fields). Unfortunately, it also broke the handling of paths containing double quotes, as it was pointed out in [3]. The solution is to stop using strconv.Unquote and write our own specialized function to deal with escape sequences. Unit tests added. [1] moby/moby#38977 [2] containerd/containerd#3159 [3] containerd/containerd#4257 Signed-off-by: Kir Kolyshkin <[email protected]>
fixes #38458
addresses kubernetes/kubernetes#35062
/proc/self/mountinfouses\040for spaces, however,parseInfoFile()did not decode those spaces in paths, therefore attempting to use
\040as a literal part of the path.
This patch un-quotes the
rootandmount pointfields to fixsituations where paths contain spaces.
Note that the
mount sourcefield is not modified, given thatthis field is documented (man
PROC(5)) as:Which I interpreted as "the format in this field is undefined".
Thanks to @remexre for reporting, and @itizir, @sergei-utinski for suggesting the patch.