From dcdc828c41ba81c00c06a4bbfba7a81828121a68 Mon Sep 17 00:00:00 2001 From: tg Date: Mon, 15 Dec 2014 22:50:11 +0000 Subject: [PATCH] =?UTF-8?q?fix=20here=20string=20parsing=20problem=20found?= =?UTF-8?q?=20by=20St=C3=A9phane=20Chazelas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.t | 14 +++++++++++--- lex.c | 25 ++++++++++++++++--------- sh.h | 4 ++-- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/check.t b/check.t index aa43e55..b006dc5 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.671 2014/11/25 21:13:19 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.672 2014/12/15 22:50:08 tg Exp $ # OpenBSD src/regress/bin/ksh updated: 2013/12/02 20:39:44 #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -27,7 +27,7 @@ # http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain expected-stdout: - @(#)MIRBSD KSH R50 2014/11/25 + @(#)MIRBSD KSH R50 2014/12/15 description: Check version of shell. stdin: @@ -36,7 +36,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R50 2014/11/25 + @(#)LEGACY KSH R50 2014/12/15 description: Check version of legacy shell. stdin: @@ -2359,6 +2359,14 @@ stdin: expected-stdout: baz --- +name: heredoc-9f +description: + Check long here strings +stdin: + cat <<< "$( : )aa" +expected-stdout: + aa +--- name: heredoc-10 description: Check direct here document assignment diff --git a/lex.c b/lex.c index a9b5ecd..3141635 100644 --- a/lex.c +++ b/lex.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.194 2014/11/19 18:44:11 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.195 2014/12/15 22:50:10 tg Exp $"); /* * states while lexing word @@ -1027,17 +1027,24 @@ yylex(int cf) /* copy word to unprefixed string ident */ sp = yylval.cp; dp = ident; - if ((cf & HEREDELIM) && (sp[1] == '<')) - while ((dp - ident) < IDENT) { - if ((c = *sp++) == CHAR) - *dp++ = *sp++; - else if ((c != OQUOTE) && (c != CQUOTE)) - break; + if ((cf & HEREDELIM) && (sp[1] == '<')) { + herestringloop: + switch ((c = *sp++)) { + case CHAR: + ++sp; + /* FALLTHROUGH */ + case OQUOTE: + case CQUOTE: + goto herestringloop; + default: + break; } - else + /* dummy value */ + *dp++ = 'x'; + } else while ((dp - ident) < IDENT && (c = *sp++) == CHAR) *dp++ = *sp++; - /* Make sure the ident array stays '\0' padded */ + /* make sure the ident array stays NUL padded */ memset(dp, 0, (ident + IDENT) - dp + 1); if (c != EOS) /* word is not unquoted */ diff --git a/sh.h b/sh.h index d7deba5..55cec8b 100644 --- a/sh.h +++ b/sh.h @@ -169,9 +169,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.705 2014/11/25 21:13:29 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.706 2014/12/15 22:50:11 tg Exp $"); #endif -#define MKSH_VERSION "R50 2014/11/25" +#define MKSH_VERSION "R50 2014/12/15" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES