From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] partition: dos: use xmalloc for unchecked allocations
Date: Tue, 22 Oct 2024 10:33:47 +0200 [thread overview]
Message-ID: <20241022083347.3248311-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241022083347.3248311-1-a.fatoum@pengutronix.de>
Instead of unconditional dereferencing of pointers that may be NULL, do a
controlled panic in the case we are out of memory by using xmalloc().
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/partitions/dos.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index 8e4edd885bfa..511d58cf0489 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -53,7 +53,7 @@ static inline int is_extended_partition(struct partition *p)
static void *read_mbr(struct block_device *blk)
{
- void *buf = malloc(SECTOR_SIZE);
+ void *buf = xmalloc(SECTOR_SIZE);
int ret;
ret = block_read(blk, buf, 0, 1);
@@ -124,7 +124,7 @@ static int dos_get_disk_signature(struct param_d *p, void *_priv)
static void dos_extended_partition(struct block_device *blk, struct dos_partition_desc *dpd,
struct partition *partition, uint32_t signature)
{
- uint8_t *buf = malloc(SECTOR_SIZE);
+ uint8_t *buf = xmalloc(SECTOR_SIZE);
uint32_t ebr_sector = partition->first_sec;
struct partition_entry *table = (struct partition_entry *)&buf[0x1be];
unsigned partno = 4;
--
2.39.5
next prev parent reply other threads:[~2024-10-22 8:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-22 8:33 [PATCH 1/2] partitions: efi: use calloc instead of kzalloc Ahmad Fatoum
2024-10-22 8:33 ` Ahmad Fatoum [this message]
2024-10-22 9:22 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241022083347.3248311-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox