summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2026-01-23 16:35:54 +0100
committerGravatar Nikias Bassen2026-01-23 16:35:54 +0100
commit57664f6394d9f96ffd54a8bb71fafb6d01528300 (patch)
treebb240c1f4b6f11b7a870e4793a56f7b07a8a7545
parentd0e6ef114aef98c410e59e30cc203489ddf3ba52 (diff)
downloadlibplist-57664f6394d9f96ffd54a8bb71fafb6d01528300.tar.gz
libplist-57664f6394d9f96ffd54a8bb71fafb6d01528300.tar.bz2
plistutil: Make sure to check for memory allocation failureHEADmaster
Addresses #302. Credit to @ylwango613.
-rw-r--r--tools/plistutil.c8
1 files changed, 7 insertions, 1 deletions
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);