Codebase list fscrypt / 2a45549
Allow filesystem links to contain leading/trailing whitespace To make manually editing linked protectors slightly more user-friendly, automatically strip any leading or trailing whitespace. E.g. treat "UUID=3a6d9a76-47f0-4f13-81bf-3332fbe984fb\n" the same as "UUID=3a6d9a76-47f0-4f13-81bf-3332fbe984fb". Update https://github.com/google/fscrypt/issues/115 Eric Biggers 4 years ago
2 changed file(s) with 34 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
281281 return mnt, nil
282282 }
283283
284 // getMountsFromLink returns the Mount object which matches the provided link.
284 // getMountFromLink returns the Mount object which matches the provided link.
285285 // This link is formatted as a tag (e.g. <token>=<value>) similar to how they
286286 // appear in "/etc/fstab". Currently, only "UUID" tokens are supported. An error
287287 // is returned if the link is invalid or we cannot load the required mount data.
289289 // functions, run UpdateMountInfo to see the change.
290290 func getMountFromLink(link string) (*Mount, error) {
291291 // Parse the link
292 link = strings.TrimSpace(link)
292293 linkComponents := strings.Split(link, "=")
293294 if len(linkComponents) != 2 {
294295 return nil, errors.Wrapf(ErrFollowLink, "link %q format is invalid", link)
254254 }
255255 }
256256
257 // Test making a filesystem link (i.e. "UUID=...") and following it, and test
258 // that leading and trailing whitespace in the link is ignored.
259 func TestGetMountFromLink(t *testing.T) {
260 mnt, err := getTestMount(t)
261 if err != nil {
262 t.Skip(err)
263 }
264 link, err := makeLink(mnt, uuidToken)
265 if err != nil {
266 t.Fatal(err)
267 }
268 linkedMnt, err := getMountFromLink(link)
269 if err != nil {
270 t.Fatal(err)
271 }
272 if linkedMnt != mnt {
273 t.Fatal("Link doesn't point to the same Mount")
274 }
275 if linkedMnt, err = getMountFromLink(link + "\n"); err != nil {
276 t.Fatal(err)
277 }
278 if linkedMnt != mnt {
279 t.Fatal("Link doesn't point to the same Mount")
280 }
281 if linkedMnt, err = getMountFromLink(" " + link + " \r\n"); err != nil {
282 t.Fatal(err)
283 }
284 if linkedMnt != mnt {
285 t.Fatal("Link doesn't point to the same Mount")
286 }
287 }
288
257289 // Benchmarks how long it takes to update the mountpoint data
258290 func BenchmarkLoadFirst(b *testing.B) {
259291 for n := 0; n < b.N; n++ {