fix here string parsing problem found by Stéphane Chazelas

This commit is contained in:
tg 2014-12-15 22:50:11 +00:00
parent 5cf460cc07
commit dcdc828c41
3 changed files with 29 additions and 14 deletions

14
check.t
View File

@ -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

25
lex.c
View File

@ -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 */

4
sh.h
View File

@ -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