diff --git a/funcs/func_env.c b/funcs/func_env.c index 072714f..d316849 100644 --- a/funcs/func_env.c +++ b/funcs/func_env.c @@ -710,12 +710,16 @@ static int file_read(struct ast_channel *chan, const char *cmd, char *data, stru char dos_state = 0; ast_debug(3, "offset=%" PRId64 ", length=%" PRId64 ", offset_offset=%" PRId64 ", length_offset=%" PRId64 "\n", offset, length, offset_offset, length_offset); for (i = offset_offset; i < flength; i += sizeof(fbuf)) { + size_t nread; char *pos; - if (fread(fbuf, 1, sizeof(fbuf), ff) < sizeof(fbuf) && !feof(ff)) { + if ((nread = fread(fbuf, 1, sizeof(fbuf), ff)) < sizeof(fbuf) && !feof(ff)) { ast_log(LOG_ERROR, "Short read?!!\n"); fclose(ff); return -1; } + if (nread < sizeof(fbuf)) { + fbuf[nread] = '\0'; + } for (pos = fbuf; pos < fbuf + sizeof(fbuf); pos++) { LINE_COUNTER(pos, format, current_length);