mntent: fix parsing lines with optional fields
authorAlyssa Ross <hi@alyssa.is>
Wed, 15 Sep 2021 22:11:55 +0000 (22:11 +0000)
committerRich Felker <dalias@aerifal.cx>
Sun, 15 May 2022 23:19:42 +0000 (19:19 -0400)
commit751bee0ee727e8d8b003c87cff77ac76f1dbecd6
treee714f49ea914ba7560c2b22a3ef4ec6a371cbfb8
parentdcb31f6b450fdeed4dc364e15cd190e8562ea227
mntent: fix parsing lines with optional fields

According to fstab(5), the last two fields are optional, but this
wasn't accepted. After this change, only the first field is required,
which matches glibc's behaviour.

Using sscanf as before, it would have been impossible to differentiate
between 0 fields and 4 fields, because sscanf would have returned 0 in
both cases due to the use of assignment suppression and %n for the
string fields (which is important to avoid copying any strings). So
instead, before calling sscanf, initialize every string to the empty
string, and then we can check which strings are empty afterwards to
know how many fields were matched.
src/misc/mntent.c