]> Savannah Git Hosting - gnulib.git/commit
mountlist: make parsing /proc/self/mountinfo more robust
authorBernhard Voelker <mail@bernhard-voelker.de>
Tue, 9 Apr 2019 20:30:16 +0000 (22:30 +0200)
committerBernhard Voelker <mail@bernhard-voelker.de>
Wed, 10 Apr 2019 06:56:34 +0000 (08:56 +0200)
commiteb8278fefa0bbf2a53b706bffb2c99ccfe5d7bd4
tree1a16c507442bf6ca707768b31201d12359e8ce3a
parentf6225ebbe70d592453edcb47f9238eb4336edca9
mountlist: make parsing /proc/self/mountinfo more robust

Cater for the following issues with mountinfo parsing (the first
one was reported by Zbigniew JÄ™drzejewski-Szmek <zbyszek@in.waw.pl>
in <https://bugs.gnu.org/35137>).

1. The fields source, target, mntroot and fstype may contain characters
like '\r'; sscanf(3) fails to read such values with the %s format
specifier because it would stop at such characters.
Example: "mount -t tmpfs tmpfs /foo^Mbar".
The only true separator in that file is the ' ' character.

2. The source field may be an empty string, which happens e.g. with
"mount -t tmpfs '' /target".

3. The fstype field may contain mangled characters as well which need
unescaping.

* lib/mountlist.c (terminate_at_blank): Add utility function.
(read_file_system_list): In the block trying to read the mountinfo file,
avoid using sscanf(3) with %s format; instead, parse the above fields
separated by spaces one by one.
This also handles the case when the source field is an empty string.
Unescape the fstype field.
ChangeLog
lib/mountlist.c