public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 1/2] dlmalloc: fix malloc range at end of ram
Date: Mon,  1 Apr 2019 22:01:49 +0200	[thread overview]
Message-ID: <20190401200150.1630-2-simon.k.r.goldschmidt@gmail.com> (raw)
In-Reply-To: <20190401200150.1630-1-simon.k.r.goldschmidt@gmail.com>

If the malloc range passed to mem_malloc_init() is at the end of address
range and 'start + size' overflows to 0, following allocations fail as
mem_malloc_end is zero (which looks like uninitialized).

Fix this by subtracting 1 of 'start + size' overflows to zero.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
---

Changes in v4: None
Changes in v3: None

 common/dlmalloc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index edaad299bb..51d3bd671a 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -603,6 +603,10 @@ void mem_malloc_init(ulong start, ulong size)
 	mem_malloc_start = start;
 	mem_malloc_end = start + size;
 	mem_malloc_brk = start;
+	if (start && size && !mem_malloc_end) {
+		/* overflow: malloc area is at end of address range */
+		mem_malloc_end--;
+	}
 
 	debug("using memory %#lx-%#lx for malloc()\n", mem_malloc_start,
 	      mem_malloc_end);
-- 
2.17.1

  reply	other threads:[~2019-04-01 20:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-01 20:01 [U-Boot] [PATCH v4 0/2] spl: full-featured heap cleanups Simon Goldschmidt
2019-04-01 20:01 ` Simon Goldschmidt [this message]
2019-04-24  3:54   ` [U-Boot] [PATCH v4 1/2] dlmalloc: fix malloc range at end of ram Simon Glass
2019-04-24 11:26     ` Tom Rini
2019-04-24 11:49       ` Simon Goldschmidt
2019-04-24 11:52         ` Tom Rini
2019-04-24 23:58           ` Simon Glass
2019-04-25  7:32             ` Simon Goldschmidt
2019-04-25 10:50               ` Tom Rini
2019-04-25 19:24                 ` Simon Goldschmidt
2019-04-29 13:06                   ` Heiko Schocher
2019-04-29 13:16                     ` Simon Goldschmidt
2019-04-29 13:20                       ` Tom Rini
2019-04-29 13:19                     ` Tom Rini
2019-04-29 15:53                       ` Simon Glass
2019-04-01 20:01 ` [U-Boot] [PATCH v4 2/2] dlmalloc: be compatible to tiny printf Simon Goldschmidt
2019-04-24  3:54   ` Simon Glass
2019-04-24 13:31   ` [U-Boot] [U-Boot, v4, " Tom Rini

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=20190401200150.1630-2-simon.k.r.goldschmidt@gmail.com \
    --to=simon.k.r.goldschmidt@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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