summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2019-01-24 00:58:20 +0200
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2019-01-27 18:58:48 +0200
commit21f9037186f8a4bfb45486b9c28dd146e9df0e00 (patch)
tree577f12e818dbe29f62cf9f4b9caf46926af876d8
parentad220b96fb01dbb6acf7e51bdd8d4d6362d96ea7 (diff)
downloadmariadb-git-21f9037186f8a4bfb45486b9c28dd146e9df0e00.tar.gz
MDEV-18360 Prevent set_max_open_files from allocating too many files
If the rlimit.rlim_cur value returned by getrlimit is not the RLIM_INFINITY magic constant, but a *very* large number, we can allocate too many open files. Restrict set_max_open_files to only return at most max_file_limit, as passed via its parameter.
-rw-r--r--mysys/my_file.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/mysys/my_file.c b/mysys/my_file.c
index 8d01285a94b..b3aef8494cb 100644
--- a/mysys/my_file.c
+++ b/mysys/my_file.c
@@ -52,10 +52,9 @@ static uint set_max_open_files(uint max_file_limit)
DBUG_PRINT("info", ("rlim_cur: %u rlim_max: %u",
(uint) rlimit.rlim_cur,
(uint) rlimit.rlim_max));
- if ((ulonglong) rlimit.rlim_cur == (ulonglong) RLIM_INFINITY)
- rlimit.rlim_cur = max_file_limit;
- if (rlimit.rlim_cur >= max_file_limit)
- DBUG_RETURN(rlimit.rlim_cur); /* purecov: inspected */
+ if ((ulonglong) rlimit.rlim_cur == (ulonglong) RLIM_INFINITY ||
+ rlimit.rlim_cur >= max_file_limit)
+ DBUG_RETURN(max_file_limit);
rlimit.rlim_cur= rlimit.rlim_max= max_file_limit;
if (setrlimit(RLIMIT_NOFILE, &rlimit))
max_file_limit= old_cur; /* Use original value */