mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Alexander Shiyan <shc_work@mail.ru>
To: barebox@lists.infradead.org
Subject: [PATCH 6/7] lib/math.c: Fix possible crash
Date: Sun, 16 Feb 2014 08:40:49 +0400	[thread overview]
Message-ID: <1392525650-5551-6-git-send-email-shc_work@mail.ru> (raw)
In-Reply-To: <1392525650-5551-1-git-send-email-shc_work@mail.ru>

Crash can be caused if xzalloc() for "numstack" fails.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 lib/math.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/lib/math.c b/lib/math.c
index a4731ed..1e3ee85 100644
--- a/lib/math.c
+++ b/lib/math.c
@@ -543,11 +543,11 @@ static arith_t evaluate_string(arith_state_t *math_state, const char *expr)
 	/* Stack of operator tokens */
 	operator *const stack = xzalloc(expr_len * sizeof(stack[0]));
 	operator *stackptr = stack;
-	arith_t result;
+	arith_t result = -1;
 
 	if (numstack == NULL || stack == NULL) {
 		errmsg = "out of memory";
-		goto err_with_custom_msg;
+		goto ret;
 	}
 
 	/* Start with a left paren */
@@ -565,7 +565,7 @@ static arith_t evaluate_string(arith_state_t *math_state, const char *expr)
 		if (arithval == '\0') {
 			if (expr == start_expr) {
 				/* Null expression */
-				numstack->val = 0;
+				result = numstack->val;
 				goto ret;
 			}
 
@@ -596,6 +596,7 @@ static arith_t evaluate_string(arith_state_t *math_state, const char *expr)
 				free(numstack->var);
 				numstack->var = NULL;
 			}
+			result = numstack->val;
 			goto ret;
 		}
 
@@ -733,7 +734,7 @@ static arith_t evaluate_string(arith_state_t *math_state, const char *expr)
 				}
 				errmsg = arith_apply(math_state, prev_op, numstack, &numstackptr);
 				if (errmsg)
-					goto err_with_custom_msg;
+					goto ret;
 			}
 			if (op == TOK_RPAREN)
 				goto err;
@@ -746,10 +747,7 @@ next: ;
 
 err:
 	errmsg = "arithmetic syntax error";
-err_with_custom_msg:
-	result = -1;
 ret:
-	result = numstack->val;
 	free(stack);
 	free(numstack);
 	math_state->errmsg = errmsg;
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-02-16  4:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-16  4:40 [PATCH 1/7] ARM: socfgpa: Remove redundant assignment Alexander Shiyan
2014-02-16  4:40 ` [PATCH 2/7] boot command: " Alexander Shiyan
2014-02-16  4:40 ` [PATCH 3/7] mtd: nand_imx: " Alexander Shiyan
2014-02-16  4:40 ` [PATCH 4/7] spi: altera_spi: " Alexander Shiyan
2014-02-16  4:40 ` [PATCH 5/7] USB gadget: " Alexander Shiyan
2014-02-16  4:40 ` Alexander Shiyan [this message]
2014-02-17  7:08   ` [PATCH 6/7] lib/math.c: Fix possible crash Sascha Hauer
2014-02-17  7:23     ` Alexander Aring
2014-02-16  4:40 ` [PATCH 7/7] scripts/kwboot: Remove redundant assignment Alexander Shiyan
2014-02-17  7:09 ` [PATCH 1/7] ARM: socfgpa: " Sascha Hauer
2014-03-08  6:41   ` Alexander Shiyan

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=1392525650-5551-6-git-send-email-shc_work@mail.ru \
    --to=shc_work@mail.ru \
    --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