summaryrefslogtreecommitdiffstats
path: root/libmount/src/utils.c
Commit message (Collapse)AuthorAgeFilesLines
* libmount: fix memory overflow [AddressSanitizer]Sami Kerola2014-11-181-1/+1
| | | | | | | | | | | | | | | | | | ==10918==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffd795b680 at pc 0x0000004447c6 bp 0x7fffd795b3e0 sp 0x7fffd795ab78 WRITE of size 129 at 0x7fffd795b680 thread T0 #0 0x4447c5 in scanf_common(void*, int, bool, char const*, __va_list_tag*) (/home/src/util-linux/.libs/lt-mount+0x4447c5) #1 0x445892 in sscanf (/home/src/util-linux/.libs/lt-mount+0x445892) #2 0x7fe78709a3d3 in get_filesystems /home/src/util-linux/libmount/src/utils.c:581:7 #3 0x7fe78709a1ba in mnt_get_filesystems /home/src/util-linux/libmount/src/utils.c:622:7 #4 0x7fe7870aa78f in do_mount_by_pattern /home/src/util-linux/libmount/src/context_mount.c:833:7 #5 0x7fe7870a9534 in mnt_context_do_mount /home/src/util-linux/libmount/src/context_mount.c:951:9 #6 0x7fe7870aab2b in mnt_context_mount /home/src/util-linux/libmount/src/context_mount.c:1051:8 #7 0x4ba9f5 in main /home/src/util-linux/sys-utils/mount.c:1107:7 #8 0x7fe785caa03f in __libc_start_main (/usr/lib/libc.so.6+0x2003f) #9 0x4b9f9c in _start (/home/src/util-linux/.libs/lt-mount+0x4b9f9c) Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: improve kernel command line parsingMike Frysinger2014-10-311-10/+24
| | | | | | | | | | | | | | | | | | | | | | | The current command line parser will stop at the first occurrence of an option, however the kernel does the opposite. So if you have: root=/dev/sda1 root=/dev/sda2 When you look for "root", the kernel will use /dev/sda2, but util-linux uses /dev/sda1. Further, if args are passed to custom init programs, the parser will pick those up as kernel options. So if you have: root=/dev/sda1 -- /foo bar=yes The kernel will stop at the "--" and pass the rest to userland. But if you look for "bar", util-linux will incorrectly return "yes". Ultimately, there's no way for util-linux to exactly parse the command line the same way as the kernel -- we don't know exactly which ones the kernel picks up and which it passes on to userland (either as env vars or as command line args). The kernel passes all unrecognized options. These updates are simple best effort. URL: https://bugs.gentoo.org/526754 Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* libmount: fix mnt_is_readonly() #ifdefKarel Zak2014-10-071-1/+1
| | | | | | | This issue affects util-linux portability to GNU/HURD Reported-by: Pino Toscano (from Red Hat) Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: add stripoff_last_component() from libmountKarel Zak2014-06-091-12/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: add mkdir_p() from libmountKarel Zak2014-06-091-37/+1Star
|
* libmount: use new debug functionsKarel Zak2014-03-211-15/+15
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add statfs_magic.hKarel Zak2014-03-061-74/+74
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: define BTRFS_TEST_MAGIC if missingBernhard Voelker2014-03-051-0/+3
| | | | | | | * libmount/src/utils.c (BTRFS_TEST_MAGIC): Conditionally add define which is used since commit v2.24-243-g6a52473. Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
* libmount: cgroup magic already definedKarel Zak2014-03-031-3/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* umount: don't use mountinfo if possibleKarel Zak2014-03-031-0/+103
| | | | | | | | | | | | | | | | | | | | | | | | The umount(8) always parses /proc/self/mountinfo to get fstype and to merge kernel mount options with userspace mount options from /run/mount/utab. This behavior is overkill in many cases and it's pretty expensive as kernel has to always compose *whole* mountinfo. This performance disadvantage is visible for crazy use-cases with huge number of mountpoints and frequently called umount(8). It seems that we can bypass /proc/self/mountinfo by statfs() to get filesystem type (statfs.f_type magic) and analyze /run/mount/utab before we parse mountinfo. This optimization is not used when: * umount(8) executed by non-root (as user= in utab is expected) * umount --lazy / --force (target is probably unreachable NFS, then use statfs() is pretty bad idea) * target is not a directory (e.g. umount /dev/sda1) * there is (deprecated) writeable mtab Reported-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add efivarfs to the list of pseudo filesystemsKarel Zak2013-12-101-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add mnt_tag_is_valid()Karel Zak2013-11-191-0/+17
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: remove dead code [coverity scan]Karel Zak2013-10-011-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: Save errno if mkostemp() failedNamhyung Kim2013-09-301-1/+3
| | | | | | | | After mkostemp() failed, umask() and free() might alter the errno to another value. Not sure those calls really changes the errno or not. But let's be more conservative. Signed-off-by: Namhyung Kim <namhyung@gmail.com>
* libmount: use memmove when overlap possibleDave Reisner2013-09-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | When unmounting some mountpoints as an unprivileged user (via the 'user' option in fstab), the umount fails. Debug output of 'umount /opt' reveals: 17760: libmount: CXT: [0x22890e0]: do umount 17760: libmount: UTILS: moving to /opt parent 17760: libmount: CXT: current directory moved to / [last_component='opt'] 17760: libmount: CXT: [0x22890e0]: umount(2) [target='pt', flags=0x00000000] valgrind shows the problem: ==23544== Source and destination overlap in memcpy(0x58d1370, 0x58d1371, 4) ==23544== at 0x4C2BBC3: memcpy@@GLIBC_2.14 (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==23544== by 0x4E537C3: mnt_chdir_to_parent (utils.c:168) ==23544== by 0x4E45E4C: mnt_context_do_umount (context_umount.c:601) ==23544== by 0x4E46513: mnt_context_umount (context_umount.c:855) ==23544== by 0x403476: umount_one (umount.c:299) ==23544== by 0x402B34: main (umount.c:629) ==23544== ref: https://bugs.archlinux.org/task/36968 Signed-off-by: Dave Reisner <dreisner@archlinux.org>
* lib/strutils: move *swith() functions to private librarySami Kerola2013-08-291-31/+0Star
| | | | | | | | Avoid code dublication in libmount and time-util. Proposed-by: Karel Zak <kzak@redhat.com> Reference: http://markmail.org/message/h7zexvqsieqngtmx Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libmount: fix typosOndrej Oprala2013-08-051-26/+26
| | | | Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
* libmount: fix memory leak [clang-analyzer]Karel Zak2013-07-091-1/+2
| | | | | Reported-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add a generic append_string() functionKarel Zak2013-07-021-0/+38
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: be more restrictive about valid tag namesKarel Zak2013-07-021-0/+12
| | | | | | | | | | # mount DUMMY=filename.img /mnt The 'DUMMY=filename.img' is a filename and should not be interpreted as tag name. The valid tag names are LABEL, UUID, PARTLABEL and PARTUUID only. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix mount.nfs segfault, rely on assert() rather than on nonnullKarel Zak2013-04-121-1/+8
| | | | | | | | | | | | | | | | | We use mnt_optstr_append_option(&o, mnt_fs_get_vfs_options(fs), NULL); in mount.nfs, unfortunately mnt_optstr_append_option() has been marked ass nonnull(1, 2). That's wrong because append and prepend should robust enough to accept NULL as option name. The patch also removes almost all __attribute__((nonnull). It seems better to rely on assert() to have usable feedback. In many cases (nonnull) is premature optimization for the library. This attribute makes sense for things like strlen() or so... Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=948274 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use O_CLOEXECKarel Zak2013-04-031-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add mnt_table_find_mountpoint()Karel Zak2013-03-251-1/+1
| | | | | | | | This is more robust implementation of mnt_get_mountpoint() that does not ignore bind mountpoints (mount --bind /mnt /mnt) as it does not depend on st_dev numbers. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: optimize tab files parsingKarel Zak2013-02-261-0/+11
| | | | | | | - ignore empty files - ignore empty tables Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: fix two misencodings in commentsBenno Schulenberg2013-02-061-1/+1
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* libmount; add recursive mkdirKarel Zak2013-01-091-0/+51
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix typosKarel Zak2012-12-121-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: make mkstemp() more robust [coverity scan]Karel Zak2012-12-121-0/+8
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't use safe_getenv() for testKarel Zak2012-12-101-1/+1
| | | | | Reported-by: Bernhard Voelker <mail@bernhard-voelker.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: avoid endless loop in mnt_get_kernel_cmdline_optionBernhard Voelker2012-12-101-3/+1Star
| | | | | | | | | | | The above function infloops when the name to search for can only be found at the beginning of /proc/cmdline but doesn't match, e.g. when searching for "ro" in "root=/dev/sda1 quiet vga=0x31a". * libmount/src/utils.c (mnt_get_kernel_cmdline_option): Replace while by for loop to ensure the pointer p is incremented. Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
* libmount: clean nonnull attribute usageKarel Zak2012-12-041-11/+11
| | | | | | | | | | - use __attribute__((nonnull) for functions where we not able to return an return code ("is", "has" and some "get" functions). - use __attribute__((nonnull) for small functions where we always modify any of the function argument (some mnt_optstr_* functions) Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add function attributes to private APIOndrej Oprala2012-11-301-1/+1
| | | | | Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: correctly interpret '*' from /etc/filesystemsKarel Zak2012-11-261-5/+24
| | | | | | | | | | | - single line with '*' in /etc/filesystems means that libmount has to read /proc/filesystems, otherwise /proc/filesystems has to be ignored - mount(2) ENODEV is no reason to break the do_mount_by_pattern() loop when trying to mount by /{etc,proc}/filesystems Reported-by: NeilBrown <neilb@suse.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add private mnt_get_kernel_cmdline_option()Karel Zak2012-11-081-0/+91
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: segfaults if neither /etc/filesystems nor/proc/filesystems existsKarel Zak2012-09-121-0/+4
| | | | | Reported-by: Juergen Daubert <jue@jue.li> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use O_CLOEXEC everywhereKarel Zak2012-09-041-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: make some string operations more robustKarel Zak2012-06-151-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add MNT_ERR_MOUNTOPTKarel Zak2012-05-281-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: Use binary search to compare pseudofsDave Reisner2012-05-231-25/+44
| | | | | | | | | It's the responsibility of anyone adding to this list in the future to ensure that the list remains sorted. While we're at it, expand this list of known pseudofs types. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
* libmount: expose mnt_get_mountpoint as external APIDave Reisner2012-04-261-0/+9
|
* libmount: add support to parse /proc/swapsKarel Zak2012-04-031-0/+11
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add configfs to pseudofs listKarel Zak2012-03-201-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: consolidate sysconf() usageKarel Zak2012-01-311-16/+13Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix resource leak [coverity scan]Karel Zak2012-01-301-3/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix negative returns [coverity scan]Karel Zak2012-01-301-6/+8
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix bugs detected by [smatch scan]Karel Zak2012-01-171-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add post-mount checks to detect ro/rwKarel Zak2012-01-161-0/+35
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add "+" prefix for options pattern (e.g findmnt -O)Karel Zak2011-12-011-1/+14
| | | | | | | | | | | | | | Examples: * findmnt --fstab -O noauto Returns all entries where is not "auto" option (including entries with "noauto" option. * findmnt --fstab -O +noauto Returns all entries where is literally "noauto" option. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=758457 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix compiler warning [-Wimplicit-function-declaration]Karel Zak2011-11-281-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib,match: split match_fstype() from libmountKarel Zak2011-11-151-29/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>