]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libmount: improve mnt_split_optstr() performance
authorKarel Zak <kzak@redhat.com>
Fri, 25 Sep 2020 15:23:18 +0000 (17:23 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 29 Sep 2020 10:06:28 +0000 (12:06 +0200)
commit4973aed09db05f41995851fd0a703cc071012d16
treed55fbf158a6ba3bc4e96b1f2c420adb7cd7070aa
parent0a9939816c1d6c57200f99432e38bf1c425a77ea
libmount: improve mnt_split_optstr() performance

This function is used by fstab (etc.) parser to split VFS, FS and
userspace options to separate lists. Unfortunately, the current
implementation reallocates the final string always when append a new
option to the string.

The new implementation pre-allocate memory for the final string
according to source string length (1/2 of the original string). This
dramatically reduces realloc() calls.

For example oss-fuzz (./test_mount_fuzz) uses 800K input string, old
version needs 28s to parse the string, new version 500ms.

Addresses: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23861
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/optstr.c