mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 11:25:35 +00:00
Check for IO stream failures in various format's truncate/seek operations
For the formats that support seek and/or truncate operations, many of the C library calls used to determine or set the current position indicator in the file stream were not being checked. In some situations, if an error occurred, a negative value would be returned from the library call. This could then be interpreted inappropriately as positional data. This patch checks the return values from these library calls before using them in subsequent operations. (issue ASTERISK-19655) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/1863/ ........ Merged revisions 362151 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 362152 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@362153 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -82,11 +82,20 @@ static int siren14seek(struct ast_filestream *fs, off_t sample_offset, int whenc
|
||||
|
||||
sample_offset = SAMPLES_TO_BYTES(sample_offset);
|
||||
|
||||
cur = ftello(fs->f);
|
||||
if ((cur = ftello(fs->f)) < 0) {
|
||||
ast_log(AST_LOG_WARNING, "Unable to determine current position in siren14 filestream %p: %s\n", fs, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
fseeko(fs->f, 0, SEEK_END);
|
||||
if (fseeko(fs->f, 0, SEEK_END) < 0) {
|
||||
ast_log(AST_LOG_WARNING, "Unable to seek to end of siren14 filestream %p: %s\n", fs, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
max = ftello(fs->f);
|
||||
if ((max = ftello(fs->f) < 0)) {
|
||||
ast_log(AST_LOG_WARNING, "Unable to determine max position in siren14 filestream %p: %s\n", fs, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (whence == SEEK_SET)
|
||||
offset = sample_offset;
|
||||
@@ -106,7 +115,19 @@ static int siren14seek(struct ast_filestream *fs, off_t sample_offset, int whenc
|
||||
|
||||
static int siren14trunc(struct ast_filestream *fs)
|
||||
{
|
||||
return ftruncate(fileno(fs->f), ftello(fs->f));
|
||||
int fd;
|
||||
off_t cur;
|
||||
|
||||
if ((fd = fileno(fs->f)) < 0) {
|
||||
ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for siren14 filestream %p: %s\n", fs, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if ((cur = ftello(fs->f) < 0)) {
|
||||
ast_log(AST_LOG_WARNING, "Unable to determine current position in siren14 filestream %p: %s\n", fs, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
/* Truncate file to current length */
|
||||
return ftruncate(fd, cur);
|
||||
}
|
||||
|
||||
static off_t siren14tell(struct ast_filestream *fs)
|
||||
|
Reference in New Issue
Block a user