From 38129c26c51b933d7db423f904ba0cd6a88ca1ed Mon Sep 17 00:00:00 2001 From: Vittorio Giovara Date: Tue, 16 Dec 2014 10:43:48 +0100 Subject: cmdutils: check file access functions return values CC: libav-stable@libav.org Bug-Id: CID 703706 --- cmdutils.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'cmdutils.c') diff --git a/cmdutils.c b/cmdutils.c index eff011c7ce..19589cea5b 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -1397,14 +1397,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) { @@ -1420,6 +1437,7 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size) (*bufptr)[(*size)++] = '\0'; } +out: fclose(f); return ret; } -- cgit v1.2.3