add -DMKSH_FAUX_EBCDIC to test the codepaths better

waking up to: Lanfear - Just Another Broken Shell
This commit is contained in:
tg 2017-04-28 11:13:49 +00:00
parent 5c2a0a1efc
commit 5743c00a5b
6 changed files with 65 additions and 14 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.159 2017/04/28 00:33:15 tg Exp $
# $MirOS: src/bin/mksh/Makefile,v 1.160 2017/04/28 11:13:45 tg Exp $
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015, 2016, 2017
@ -94,13 +94,18 @@ CLEANFILES+= ${GENERATED}
${PROG} beforedepend: ${GENERATED}
REGRESS_CATEGORIES:=shell:legacy-no,int:32,shell:ebcdic-no,shell:ascii-yes,shell:textmode-no,shell:binmode-yes,fastbox
.if !empty(GCEXTRA:M-DMKSH_FAUX_EBCDIC)
REGRESS_CATEGORIES:=${REGRESS_CATEGORIES},shell:faux-ebcdic
.endif
regress: ${PROG} check.pl check.t
-rm -rf regress-dir
mkdir -p regress-dir
echo export FNORD=666 >regress-dir/.mkshrc
HOME=$$(realpath regress-dir) perl ${SRCDIR}/check.pl \
-s ${SRCDIR}/check.t -v -p ./${PROG} \
-C shell:legacy-no,int:32,shell:ebcdic-no,shell:ascii-yes,shell:textmode-no,shell:binmode-yes,fastbox
-C ${REGRESS_CATEGORIES}
TEST_BUILD_ENV:= TARGET_OS= CPP=
TEST_BUILD_ENV+= HAVE_STRING_POOLING=0

43
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.781 2017/04/28 03:28:14 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.782 2017/04/28 11:13:45 tg Exp $
# -*- mode: sh -*-
#-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -9389,6 +9389,7 @@ expected-stdout:
name: varexpand-special-quote
description:
Check special ${var@Q} expansion for quoted strings
category: !shell:faux-ebcdic
stdin:
set +U
i=x
@ -9408,6 +9409,29 @@ expected-stdout:
typeset v='a b'
typeset w=$'c\nd\240e\u20ACf'
---
name: varexpand-special-quote-faux-EBCDIC
description:
Check special ${var@Q} expansion for quoted strings
category: shell:faux-ebcdic
stdin:
set +U
i=x
j=a\ b
k=$'c
d\xA0''e<EFBFBD>'
print -r -- "<i=$i j=$j k=$k>"
s="u=${i@Q} v=${j@Q} w=${k@Q}"
print -r -- "s=\"$s\""
eval "$s"
typeset -p u v w
expected-stdout:
<i=x j=a b k=c
d猬<EFBFBD>>
s="u=x v='a b' w=$'c\nd猬\u20ACf'"
typeset u=x
typeset v='a b'
typeset w=$'c\nd猬\u20ACf'
---
name: varexpand-null-1
description:
Ensure empty strings expand emptily
@ -13009,6 +13033,7 @@ name: duffs-device
description:
Check that the compiler did not optimise-break them
(lex.c has got a similar one in SHEREDELIM)
category: !shell:faux-ebcdic
stdin:
set +U
s=
@ -13021,6 +13046,22 @@ stdin:
expected-stdout:
typeset s=$'\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\E\034\035\036\037 !"#$%&\047()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\u00A0\u20AC\uFFFD\357\277\276\357\277\277\360\220\200\200.'
---
name: duffs-device-faux-EBCDIC
description:
Check that the compiler did not optimise-break them
category: shell:faux-ebcdic
stdin:
set +U
s=
typeset -i1 i=0
while (( ++i < 256 )); do
s+=${i#1#}
done
s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
typeset -p s
expected-stdout:
typeset s=$'\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\E\034\035\036\037 !"#$%&\047()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237嵗╯丰戍貝物洎悖停眾斯須號獄播噶擱藏霰匸<E99CB0>帊昅恘倳眑婭笫崷窙嗲睧颬睼麧緗鴇膹擨闀貘覷鏷禴矙𡜍𦶠<F0A19C8D>\u00A0\u20AC\uFFFD嚙橘蕞礒220\200\200.'
---
name: stateptr-underflow
description:
This check overflows an Xrestpos stored in a short in R40

4
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.341 2017/04/28 01:15:50 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.342 2017/04/28 11:13:47 tg Exp $");
extern char **environ;
@ -236,7 +236,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
ssize_t k;
#endif
#ifdef MKSH_EBCDIC
#if defined(MKSH_EBCDIC) || defined(MKSH_FAUX_EBCDIC)
ebcdic_init();
#endif
set_ifs(TC_IFSWS);

4
misc.c
View File

@ -32,7 +32,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.268 2017/04/28 03:46:49 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.269 2017/04/28 11:13:48 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
@ -1188,7 +1188,7 @@ print_value_quoted(struct shf *shf, const char *s)
if (0)
/* FALLTHROUGH */
default:
#ifdef MKSH_EBCDIC
#if defined(MKSH_EBCDIC) || defined(MKSH_FAUX_EBCDIC)
if (ksh_isctrl(c))
#else
if (c < 32 || c > 0x7E)

13
sh.h
View File

@ -175,7 +175,7 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.827 2017/04/28 03:51:13 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.828 2017/04/28 11:13:48 tg Exp $");
#endif
#define MKSH_VERSION "R55 2017/04/27"
@ -1467,7 +1467,7 @@ EXTERN char ifs0;
/* identity transform of octet */
#define ord(c) ((unsigned int)(unsigned char)(c))
#ifdef MKSH_EBCDIC
#if defined(MKSH_EBCDIC) || defined(MKSH_FAUX_EBCDIC)
EXTERN unsigned short ebcdic_map[256];
EXTERN unsigned char ebcdic_rtt_toascii[256];
EXTERN unsigned char ebcdic_rtt_fromascii[256];
@ -1477,17 +1477,20 @@ extern void ebcdic_init(void);
/* two-way round-trip conversion, for general use */
#define rtt2asc(c) ebcdic_rtt_toascii[(unsigned char)(c)]
#define asc2rtt(c) ebcdic_rtt_fromascii[(unsigned char)(c)]
/* control character foo */
#define ksh_isctrl(c) (ord(c) < 0x40 || ord(c) == 0xFF)
/* case-independent char comparison */
#define ksh_eq(c,u,l) (ord(c) == ord(u) || ord(c) == ord(l))
#else
#define asciibetical(c) ord(c)
#define rtt2asc(c) ((unsigned char)(c))
#define asc2rtt(c) ((unsigned char)(c))
#define ksh_isctrl(c) (((c) & 0x7F) < 0x20 || (c) == 0x7F)
#define ksh_eq(c,u,l) ((ord(c) | 0x20) == ord(l))
#endif
/* control character foo */
#ifdef MKSH_EBCDIC
#define ksh_isctrl(c) (ord(c) < 0x40 || ord(c) == 0xFF)
#else
#define ksh_isctrl(c) ((ord(c) & 0x7F) < 0x20 || (c) == 0x7F)
#endif
/* new fast character classes */
#define ctype(c,t) tobool(ksh_ctypes[rtt2asc(c)] & (t))
/* helper functions */

6
shf.c
View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.89 2017/04/28 04:13:19 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.90 2017/04/28 11:13:49 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -1217,7 +1217,7 @@ set_ifs(const char *s)
ksh_ctypes[rtt2asc(*s++)] |= CiIFS;
}
#ifdef MKSH_EBCDIC
#if defined(MKSH_EBCDIC) || defined(MKSH_FAUX_EBCDIC)
#include <locale.h>
void
@ -1229,10 +1229,12 @@ ebcdic_init(void)
while (i--)
ebcdic_rtt_toascii[i] = i;
setlocale(LC_ALL, "");
#ifdef MKSH_EBCDIC
if (__etoa_l(ebcdic_rtt_toascii, 256) != 256) {
write(2, "mksh: could not map EBCDIC to ASCII\n", 36);
exit(255);
}
#endif
i = 0;
do {