[PATCH] parser: preserve characters on heap in backquote parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This bug report for BusyBox ash also applies to dash:

   https://bugs.busybox.net/show_bug.cgi?id=9246

With an 8MB stack the test case results in a segfault.

Instead of using alloca() to preserve characters keep them on the
memalloc stack.  With this change the test case returns:

   $ dash test_case
   test_case: 3141: test_case: Syntax error: Unterminated quoted string

If the heap is reduced to the same size as the stack, 8MB:

   $ ulimit -S -d 8192
   $ dash test_case
   test_case: 0: test_case: Out of space

Signed-off-by: Ron Yorston <rmy@xxxxxxxxx>
---
 src/parser.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/parser.c b/src/parser.c
index c4e6378..6efa8e2 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1373,8 +1373,7 @@ parsebackq: {
 	str = NULL;
 	savelen = out - (char *)stackblock();
 	if (savelen > 0) {
-		str = alloca(savelen);
-		memcpy(str, stackblock(), savelen);
+		str = grabstackstr(out);
 	}
         if (oldstyle) {
                 /* We must read until the closing backquote, giving special
-- 
2.19.1




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux