From 7c37434360f1c49975c286566efc3f0c935a84ef Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 19 Oct 2021 02:50:34 +0200 Subject: utils: Fix bad malloc result check in buffer_read_from_filename and test arguments for NULL --- src/utils.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils.c b/src/utils.c index b03f13b..7b10a08 100644 --- a/src/utils.c +++ b/src/utils.c @@ -257,6 +257,10 @@ LIBIMOBILEDEVICE_GLUE_API int buffer_read_from_filename(const char *filename, ch FILE *f; uint64_t size; + if (!filename || !buffer || !length) { + return 0; + } + *length = 0; f = fopen(filename, "rb"); @@ -275,7 +279,7 @@ LIBIMOBILEDEVICE_GLUE_API int buffer_read_from_filename(const char *filename, ch *buffer = (char*)malloc(sizeof(char)*(size+1)); - if (!buffer) { + if (*buffer == NULL) { return 0; } -- cgit v1.1-32-gdbae