summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--funcs/func_env.c2
-rw-r--r--tests/test_func_file.c6
2 files changed, 7 insertions, 1 deletions
diff --git a/funcs/func_env.c b/funcs/func_env.c
index 0daa7f48d..26bd09c13 100644
--- a/funcs/func_env.c
+++ b/funcs/func_env.c
@@ -561,7 +561,7 @@ static int file_read(struct ast_channel *chan, const char *cmd, char *data, stru
/* Don't go past the length requested */
if (off_i + toappend > offset + length) {
- toappend = offset + length - off_i;
+ toappend = MIN(offset + length - off_i, flength - off_i);
}
ast_str_append_substr(buf, len, fbuf, toappend);
diff --git a/tests/test_func_file.c b/tests/test_func_file.c
index 4ebc87caf..834907578 100644
--- a/tests/test_func_file.c
+++ b/tests/test_func_file.c
@@ -63,6 +63,12 @@ static struct {
/* No length */
{ "123456789", "-5", "56789" },
{ "123456789", "4", "56789" },
+ /* Passed file length */
+ { "123456789", "8,10", "9" },
+ { "123456789", "10,1", "" },
+ /* Middle of file */
+ { "123456789", "2,5", "34567" },
+ { "123456789", "-7,5", "34567" },
/* Line mode, 4 ways of specifying the first character */
{ "123\n456\n789\n", "0,1,l", "123\n" },
{ "123\n456\n789\n", "-3,1,l", "123\n" },