Skip to content

Commit 98bc7e2

Browse files
KunWuChankees
authored andcommitted
pstore/zone: Add a null pointer check to the psz_kmsg_read
kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Ensure the allocation was successful by checking the pointer validity. Signed-off-by: Kunwu Chan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent a28655c commit 98bc7e2

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/pstore/zone.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ static ssize_t psz_kmsg_read(struct pstore_zone *zone,
973973
char *buf = kasprintf(GFP_KERNEL, "%s: Total %d times\n",
974974
kmsg_dump_reason_str(record->reason),
975975
record->count);
976+
if (!buf)
977+
return -ENOMEM;
976978
hlen = strlen(buf);
977979
record->buf = krealloc(buf, hlen + size, GFP_KERNEL);
978980
if (!record->buf) {

0 commit comments

Comments
 (0)