From d6cd9b06244b71385a93859f213f0c8f3791fe6b Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 4 Feb 2025 10:33:31 +0000 Subject: [PATCH] lenses/fstab.aug: Allow individual mount options to be empty Mount allows mount-option fields to be empty (I think it ignores them), but augeas gave an error. Allow this to be parsed, preserving the empty option on write. Example: /dev/mapper/vg00-vartmp /var/tmp xfs rw,,nodev,nosuid,noexec,relatime 0 0 Note this generalises earlier commit 5246ef0738 ("lenses/fstab.aug: Allow comma after the last option (#838)") since "," appearing at the end of the option list is a special case of this. Fixes: https://issues.redhat.com/browse/RHEL-77279 Fixes: https://github.com/hercules-team/augeas/issues/832 Signed-off-by: Richard W.M. Jones --- lenses/fstab.aug | 9 +++++---- lenses/tests/test_fstab.aug | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lenses/fstab.aug b/lenses/fstab.aug index 8784961da..92a97a230 100644 --- a/lenses/fstab.aug +++ b/lenses/fstab.aug @@ -24,11 +24,12 @@ module Fstab = Build.opt_list lns comma (* A mount option label can't contain comma, comment, equals, or space *) - let optlabel = /[^,#= \n\t]+/ + let mntoptlabel = /[^,#= \n\t]+/ - let comma_sep_list (l:string) = + let mntopt_list (l:string) = let value = [ label "value" . Util.del_str "=" . ( store Rx.neg1 )? ] in - let lns = [ label l . store optlabel . value? ] in + let mntopt = [ label l . store mntoptlabel . value? ] in + let lns = mntopt? in Build.opt_list lns comma let record = [ seq "mntent" . @@ -36,7 +37,7 @@ module Fstab = [ label "spec" . store spec ] . sep_tab . [ label "file" . store file ] . sep_tab . vfstype_list "vfstype" . - (sep_tab . comma_sep_list "opt" . + (sep_tab . mntopt_list "opt" . (sep_tab . [ label "dump" . store /[0-9]+/ ] . ( sep_spc . [ label "passno" . store /[0-9]+/ ])? )? )? . Util.comment_or_eol ] diff --git a/lenses/tests/test_fstab.aug b/lenses/tests/test_fstab.aug index 438f619a9..cc2398486 100644 --- a/lenses/tests/test_fstab.aug +++ b/lenses/tests/test_fstab.aug @@ -156,6 +156,30 @@ module Test_fstab = { "#comment" = "device at install: /dev/sda3" } } + (* Bug #832 - Allow comma after the last option *) + test Fstab.lns get "/dev/mapper/foo-bar / xfs defaults, 0 0\n" = + { "1" + { "spec" = "/dev/mapper/foo-bar" } + { "file" = "/" } + { "vfstype" = "xfs" } + { "opt" = "defaults" } + { "dump" = "0" } + { "passno" = "0" } + } + + (* RHEL-77279 - Allow empty option *) + test Fstab.lns get "/dev/mapper/foo-bar / xfs rw,,nodev 0 0\n" = + { "1" + { "spec" = "/dev/mapper/foo-bar" } + { "file" = "/" } + { "vfstype" = "xfs" } + { "opt" = "rw" } + { "opt" = "" } + { "opt" = "nodev" } + { "dump" = "0" } + { "passno" = "0" } + } + (* Local Variables: *) (* mode: caml *) (* End: *)