Rename FISH_READ_BYTE_LIMIT to fish_read_limit

Fixes #4414
This commit is contained in:
Aaron Gyes 2017-10-14 08:22:57 -07:00
parent 18b06f3768
commit 7be8a1707c
5 changed files with 14 additions and 14 deletions

View file

@ -475,7 +475,7 @@ The exit status of the last run command substitution is available in the <a href
Only part of the output can be used, see <a href='#expand-index-range'>index range expansion</a> 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:

View file

@ -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

View file

@ -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);
}

View file

@ -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

View file

@ -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)