diff options
| author | 2026-01-23 16:35:54 +0100 | |
|---|---|---|
| committer | 2026-01-23 16:35:54 +0100 | |
| commit | 57664f6394d9f96ffd54a8bb71fafb6d01528300 (patch) | |
| tree | bb240c1f4b6f11b7a870e4793a56f7b07a8a7545 /tools | |
| parent | d0e6ef114aef98c410e59e30cc203489ddf3ba52 (diff) | |
| download | libplist-57664f6394d9f96ffd54a8bb71fafb6d01528300.tar.gz libplist-57664f6394d9f96ffd54a8bb71fafb6d01528300.tar.bz2 | |
plistutil: Make sure to check for memory allocation failure
Addresses #302.
Credit to @ylwango613.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/plistutil.c | 8 |
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[]) | |||
| 219 | plist_entire = malloc(sizeof(char) * read_capacity); | 219 | plist_entire = malloc(sizeof(char) * read_capacity); |
| 220 | if(plist_entire == NULL) | 220 | if(plist_entire == NULL) |
| 221 | { | 221 | { |
| 222 | fprintf(stderr, "ERROR: Failed to allocate buffer to read from stdin"); | 222 | fprintf(stderr, "ERROR: Failed to allocate buffer to read from stdin\n"); |
| 223 | free(options); | 223 | free(options); |
| 224 | return 1; | 224 | return 1; |
| 225 | } | 225 | } |
| @@ -278,6 +278,12 @@ int main(int argc, char *argv[]) | |||
| 278 | fstat(fileno(iplist), &filestats); | 278 | fstat(fileno(iplist), &filestats); |
| 279 | 279 | ||
| 280 | plist_entire = (char *) malloc(sizeof(char) * (filestats.st_size + 1)); | 280 | plist_entire = (char *) malloc(sizeof(char) * (filestats.st_size + 1)); |
| 281 | if(plist_entire == NULL) | ||
| 282 | { | ||
| 283 | fprintf(stderr, "ERROR: Failed to allocate buffer to read from file\n"); | ||
| 284 | free(options); | ||
| 285 | return 1; | ||
| 286 | } | ||
| 281 | read_size = fread(plist_entire, sizeof(char), filestats.st_size, iplist); | 287 | read_size = fread(plist_entire, sizeof(char), filestats.st_size, iplist); |
| 282 | plist_entire[read_size] = '\0'; | 288 | plist_entire[read_size] = '\0'; |
| 283 | fclose(iplist); | 289 | fclose(iplist); |
