cmdutils: check file access functions return values
CC: libav-stable@libav.org
Bug-Id: CID 703706
(cherry picked from commit 38129c26c5
)
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
This commit is contained in:

committed by
Luca Barbato

parent
1411f073fd
commit
cbfdbba58e
28
cmdutils.c
28
cmdutils.c
@@ -1395,14 +1395,31 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
return AVERROR(errno);
|
return AVERROR(errno);
|
||||||
}
|
}
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
*size = ftell(f);
|
ret = fseek(f, 0, SEEK_END);
|
||||||
fseek(f, 0, SEEK_SET);
|
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);
|
*bufptr = av_malloc(*size + 1);
|
||||||
if (!*bufptr) {
|
if (!*bufptr) {
|
||||||
av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n");
|
av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n");
|
||||||
fclose(f);
|
ret = AVERROR(ENOMEM);
|
||||||
return AVERROR(ENOMEM);
|
goto out;
|
||||||
}
|
}
|
||||||
ret = fread(*bufptr, 1, *size, f);
|
ret = fread(*bufptr, 1, *size, f);
|
||||||
if (ret < *size) {
|
if (ret < *size) {
|
||||||
@@ -1418,6 +1435,7 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
|
|||||||
(*bufptr)[(*size)++] = '\0';
|
(*bufptr)[(*size)++] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user