aboutsummaryrefslogtreecommitdiffstats
path: root/cmdutils.c
diff options
context:
space:
mode:
authorVittorio Giovara <vittorio.giovara@gmail.com>2014-12-16 10:43:48 +0100
committerLuca Barbato <lu_zero@gentoo.org>2015-01-12 23:14:06 +0100
commitcbfdbba58e1460bd0791911ad84a6c76b5500a0e (patch)
tree995a76abf2f80e59edd5e6436a008036ccc7d2cb /cmdutils.c
parent1411f073fdceeff1f39dbaa035c3c0275f69095f (diff)
downloadffmpeg-cbfdbba58e1460bd0791911ad84a6c76b5500a0e.tar.gz
cmdutils: check file access functions return values
CC: libav-stable@libav.org Bug-Id: CID 703706 (cherry picked from commit 38129c26c51b933d7db423f904ba0cd6a88ca1ed) Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'cmdutils.c')
-rw-r--r--cmdutils.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/cmdutils.c b/cmdutils.c
index 202b288a60..a7b00604d3 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -1395,14 +1395,31 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
strerror(errno));
return AVERROR(errno);
}
- fseek(f, 0, SEEK_END);
- *size = ftell(f);
- fseek(f, 0, SEEK_SET);
+
+ ret = fseek(f, 0, SEEK_END);
+ if (ret == -1) {
+ ret = AVERROR(errno);
+ goto out;
+ }
+
+ ret = ftell(f);
+ if (ret < 0) {
+ ret = AVERROR(errno);
+ goto out;
+ }
+ *size = ret;
+
+ ret = fseek(f, 0, SEEK_SET);
+ if (ret == -1) {
+ ret = AVERROR(errno);
+ goto out;
+ }
+
*bufptr = av_malloc(*size + 1);
if (!*bufptr) {
av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n");
- fclose(f);
- return AVERROR(ENOMEM);
+ ret = AVERROR(ENOMEM);
+ goto out;
}
ret = fread(*bufptr, 1, *size, f);
if (ret < *size) {
@@ -1418,6 +1435,7 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
(*bufptr)[(*size)++] = '\0';
}
+out:
fclose(f);
return ret;
}