[klibc] [klibc:update-dash] dash: expand: Fix trailing newlines processing in backquote expanding

klibc-bot for Nikolai Merinov n.merinov at inango-systems.com
Sat Mar 28 14:49:42 PDT 2020


Commit-ID:  42c84c0c2ed8f5b9a81bd70582edfa9d7ead08be
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=42c84c0c2ed8f5b9a81bd70582edfa9d7ead08be
Author:     Nikolai Merinov <n.merinov at inango-systems.com>
AuthorDate: Mon, 29 Apr 2019 19:13:37 +0500
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sat, 28 Mar 2020 21:42:55 +0000

[klibc] dash: expand: Fix trailing newlines processing in backquote expanding

[ dash commit c4f4ee8ecf85834811c252fc1df3892863572bbd ]

According to POSIX.1-2008 we should remove newlines only at the end of
the substitution. Newlines-only substitions causes dash to remove
newlines before beggining of the substitution. The following code:

    cat <<END
    1
    $(echo "")
    2
    END

prints "1<newline>2" instead of expected "1<newline><newline>2".

This patch fixes trailing newlines processing in backquote expanding.

Signed-off-by: Nikolai Merinov <n.merinov at inango-systems.com>
Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/dash/expand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usr/dash/expand.c b/usr/dash/expand.c
index 562a4869..175f037b 100644
--- a/usr/dash/expand.c
+++ b/usr/dash/expand.c
@@ -525,7 +525,7 @@ read:
 
 	/* Eat all trailing newlines */
 	dest = expdest;
-	for (; dest > (char *)stackblock() && dest[-1] == '\n';)
+	for (; dest > ((char *)stackblock() + startloc) && dest[-1] == '\n';)
 		STUNPUTC(dest);
 	expdest = dest;
 


More information about the klibc mailing list