Fix checking whether we can initialize the datadir

Existance of .bash_history is ignored
Every file is checked separately, so we don't get false negative check when *.err matches e.g. 'mysql test zzz.org.err' content
Related: #1356897
This commit is contained in:
Honza Horak 2017-06-07 16:01:09 +02:00
parent b23629497b
commit 25e7bbfef5
2 changed files with 13 additions and 8 deletions

View File

@ -1403,8 +1403,10 @@ fi
%changelog %changelog
* Fri Jun 09 2017 Honza Horak <hhorak@redhat.com> - 3:10.1.24-3 * Fri Jun 09 2017 Honza Horak <hhorak@redhat.com> - 3:10.1.24-3
Downstream script mariadb-prepare-db-dir fixed for CVE-2017-3265 - Downstream script mariadb-prepare-db-dir fixed for CVE-2017-3265
Resolves: #1458940 Resolves: #1458940
- Check properly that datadir includes only expected files
Related: #1356897
* Wed Jun 07 2017 Michal Schorm <mschorm@redhat.com> - 3:10.1.24-2 * Wed Jun 07 2017 Michal Schorm <mschorm@redhat.com> - 3:10.1.24-2
- Fixed incorrect Jemalloc initialization; #1459671 - Fixed incorrect Jemalloc initialization; #1459671

View File

@ -5,24 +5,27 @@
source "`dirname ${BASH_SOURCE[0]}`/mysql-scripts-common" source "`dirname ${BASH_SOURCE[0]}`/mysql-scripts-common"
export LC_ALL=C
# Returns content of the specified directory # Returns content of the specified directory
# If listing files fails, fake-file is returned so which means # If listing files fails, fake-file is returned so which means
# we'll behave like there was some data initialized # we'll behave like there was some data initialized
# Some files or directories are fine to be there, so those are
# explicitly removed from the listing
# @param <dir> datadir # @param <dir> datadir
ls_check_datadir () list_datadir ()
{ {
ls -A "$1" 2>/dev/null ( ls -1A "$1" 2>/dev/null || echo "fake-file" ) | grep -v \
test $? -eq 0 || echo "fake-file" -e '^lost+found$' \
-e '\.err$' \
-e '^.bash_history$'
} }
# Checks whether datadir should be initialized # Checks whether datadir should be initialized
# @param <dir> datadir # @param <dir> datadir
should_initialize () should_initialize ()
{ {
case `ls_check_datadir "$1"` in test -z "$(list_datadir "$1")"
""|lost+found|*.err) true ;;
*) false ;;
esac
} }
# If two args given first is user, second is group # If two args given first is user, second is group