From 57664f6394d9f96ffd54a8bb71fafb6d01528300 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 23 Jan 2026 16:35:54 +0100 Subject: plistutil: Make sure to check for memory allocation failure Addresses #302. Credit to @ylwango613. --- tools/plistutil.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/plistutil.c b/tools/plistutil.c index c984da2..56f25fd 100644 --- a/tools/plistutil.c +++ b/tools/plistutil.c @@ -219,7 +219,7 @@ int main(int argc, char *argv[]) plist_entire = malloc(sizeof(char) * read_capacity); if(plist_entire == NULL) { - fprintf(stderr, "ERROR: Failed to allocate buffer to read from stdin"); + fprintf(stderr, "ERROR: Failed to allocate buffer to read from stdin\n"); free(options); return 1; } @@ -278,6 +278,12 @@ int main(int argc, char *argv[]) fstat(fileno(iplist), &filestats); plist_entire = (char *) malloc(sizeof(char) * (filestats.st_size + 1)); + if(plist_entire == NULL) + { + fprintf(stderr, "ERROR: Failed to allocate buffer to read from file\n"); + free(options); + return 1; + } read_size = fread(plist_entire, sizeof(char), filestats.st_size, iplist); plist_entire[read_size] = '\0'; fclose(iplist); -- cgit v1.1-32-gdbae