From 7be8a1707c4b6a36e0634d791963536e259f5b04 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Sat, 14 Oct 2017 08:22:57 -0700 Subject: [PATCH] Rename FISH_READ_BYTE_LIMIT to fish_read_limit Fixes #4414 --- doc_src/index.hdr.in | 2 +- doc_src/read.txt | 2 +- src/env.cpp | 8 ++++---- tests/read.in | 14 +++++++------- tests/test_cmdsub.in | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in index 3ce98bb75..433b1005e 100644 --- a/doc_src/index.hdr.in +++ b/doc_src/index.hdr.in @@ -475,7 +475,7 @@ The exit status of the last run command substitution is available in the index range expansion for details. -Fish has a default limit of 10 MiB on the amount of data a command substitution can output. If the limit is exceeded the entire command, not just the substitution, is failed and `$status` is set to 122. You can modify the limit by setting the `FISH_READ_BYTE_LIMIT` variable at any time including in the environment before fish starts running. If you set it to zero then no limit is imposed. This is a safety mechanism to keep the shell from consuming an too much memory if a command outputs an unreasonable amount of data. Note that this limit also affects how much data the `read` command will process. +Fish has a default limit of 10 MiB on the amount of data a command substitution can output. If the limit is exceeded the entire command, not just the substitution, is failed and `$status` is set to 122. You can modify the limit by setting the `fish_read_limit` variable at any time including in the environment before fish starts running. If you set it to zero then no limit is imposed. This is a safety mechanism to keep the shell from consuming an too much memory if a command outputs an unreasonable amount of data. Note that this limit also affects how much data the `read` command will process. Examples: diff --git a/doc_src/read.txt b/doc_src/read.txt index f3c886076..96fee08a2 100644 --- a/doc_src/read.txt +++ b/doc_src/read.txt @@ -61,7 +61,7 @@ Otherwise, it is set to 0. In order to protect the shell from consuming too many system resources, `read` will only consume a maximum of 10 MiB (1048576 bytes); if the terminator is not reached before this limit then VARIABLE is set to empty and the exit status is set to 122. This limit can be altered with the -`FISH_READ_BYTE_LIMIT` variable. If set to 0 (zero), the limit is removed. +`fish_read_limit` variable. If set to 0 (zero), the limit is removed. \subsection read-history Using another read history file diff --git a/src/env.cpp b/src/env.cpp index c37c0134c..50157cd2c 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -69,7 +69,7 @@ extern char **environ; // Limit `read` to 10 MiB (bytes not wide chars) by default. This can be overridden by the -// FISH_READ_BYTE_LIMIT variable. +// fish_read_limit variable. #define READ_BYTE_LIMIT 10 * 1024 * 1024 size_t read_byte_limit = READ_BYTE_LIMIT; @@ -680,11 +680,11 @@ bool env_set_pwd() { /// Allow the user to override the limit on how much data the `read` command will process. /// This is primarily for testing but could be used by users in special situations. void env_set_read_limit() { - auto read_byte_limit_var = env_get(L"FISH_READ_BYTE_LIMIT"); + auto read_byte_limit_var = env_get(L"fish_read_limit"); if (!read_byte_limit_var.missing_or_empty()) { size_t limit = fish_wcstoull(read_byte_limit_var->as_string().c_str()); if (errno) { - debug(1, "Ignoring FISH_READ_BYTE_LIMIT since it is not valid"); + debug(1, "Ignoring fish_read_limit since it is not valid"); } else { read_byte_limit = limit; } @@ -846,7 +846,7 @@ static void setup_var_dispatch_table() { var_dispatch_table.emplace(L"fish_escape_delay_ms", handle_escape_delay_change); var_dispatch_table.emplace(L"LINES", handle_term_size_change); var_dispatch_table.emplace(L"COLUMNS", handle_term_size_change); - var_dispatch_table.emplace(L"FISH_READ_BYTE_LIMIT", handle_read_limit_change); + var_dispatch_table.emplace(L"fish_read_limit", handle_read_limit_change); var_dispatch_table.emplace(L"fish_history", handle_fish_history_change); var_dispatch_table.emplace(L"TZ", handle_tz_change); } diff --git a/tests/read.in b/tests/read.in index 4561aa987..fcd2e071d 100644 --- a/tests/read.in +++ b/tests/read.in @@ -135,13 +135,13 @@ rm $path # The following tests verify that `read` correctly handles the limit on the # number of bytes consumed. # -set FISH_READ_BYTE_LIMIT 8192 +set fish_read_limit 8192 set line abcdefghijklmnopqrstuvwxyz # Ensure the `read` command terminates if asked to read too much data. The var # should be empty. We throw away any data we read if it exceeds the limit on # what we consider reasonable. -yes $line | dd bs=1024 count=(math "1 + $FISH_READ_BYTE_LIMIT / 1024") ^/dev/null | read --null x +yes $line | dd bs=1024 count=(math "1 + $fish_read_limit / 1024") ^/dev/null | read --null x if test $status -ne 122 echo reading too much data did not terminate with failure status end @@ -155,7 +155,7 @@ and echo reading too much data resulted in a var with unexpected data # Ensure the `read` command terminates if asked to read too much data even if # given an explicit limit. The var should be empty. We throw away any data we # read if it exceeds the limit on what we consider reasonable. -yes $line | read --null --nchars=(math "$FISH_READ_BYTE_LIMIT + 1") x +yes $line | read --null --nchars=(math "$fish_read_limit + 1") x if test $status -ne 122 echo reading too much data did not terminate with failure status end @@ -178,21 +178,21 @@ if test $exp_length -ne $act_length end # Confirm we can read exactly up to the limit. -yes $line | read --null --nchars $FISH_READ_BYTE_LIMIT x +yes $line | read --null --nchars $fish_read_limit x if test $status -ne 0 echo the read of the max amount of data with --nchars failed unexpectedly end -if test (string length "$x") -ne $FISH_READ_BYTE_LIMIT +if test (string length "$x") -ne $fish_read_limit echo reading the max amount of data with --nchars failed the length test end # Same as previous test but limit the amount of data fed to `read` rather than # using the `--nchars` flag. -yes $line | dd bs=1024 count=(math "$FISH_READ_BYTE_LIMIT / 1024") ^/dev/null | read --null x +yes $line | dd bs=1024 count=(math "$fish_read_limit / 1024") ^/dev/null | read --null x if test $status -ne 0 echo the read of the max amount of data failed unexpectedly end -if test (string length "$x") -ne $FISH_READ_BYTE_LIMIT +if test (string length "$x") -ne $fish_read_limit echo reading the max amount of data with --nchars failed the length test end diff --git a/tests/test_cmdsub.in b/tests/test_cmdsub.in index 29507a7f0..4ce23173c 100644 --- a/tests/test_cmdsub.in +++ b/tests/test_cmdsub.in @@ -1,7 +1,7 @@ # This tests various corner cases involving command substitution. Most # importantly the limits on the amount of data we'll substitute. -set FISH_READ_BYTE_LIMIT 512 +set fish_read_limit 512 function subme set -l x (string repeat -n $argv x)