put upper bound on data read will consume

This puts a hard upper bound of 10 MiB on the amount of data that read
will consume. This is to avoid having the shell consume an unreasonable
amount of memory, possibly causing the system to enter a OOM condition,
if the user does something non-sensical.

Fixes #3712
This commit is contained in:
Kurtis Rader
2017-02-07 17:21:35 -08:00
parent f27407bbf9
commit af7f5f42b6
8 changed files with 125 additions and 20 deletions

View File

@@ -48,6 +48,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include "path.h"
#include "proc.h"
#include "reader.h"
#include "signal.h"
#include "wutil.h" // IWYU pragma: keep
// PATH_MAX may not exist.
@@ -318,6 +319,8 @@ static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *cmds)
/// Various things we need to initialize at run-time that don't really fit any of the other init
/// routines.
static void misc_init() {
env_set_read_limit();
// If stdout is open on a tty ensure stdio is unbuffered. That's because those functions might
// be intermixed with `write()` calls and we need to ensure the writes are not reordered. See
// issue #3748.